Hi, All,
I’ve come across a strange behavior in my local environment for WebAPI. I have a JPA repository that I assign a ‘named entity graph’ that gives query hints about how the object should be retrieved from the db. Here’s the 2 queries that get built (the first being bad from Tomcat 7.0 hosted, other my local run as standalone app):
select protocol0_.id as id1_2_0_, cohortdefi1_.id as id1_3_1_, cohortdefi2_.id as id1_4_2_, simulation4_.id as id1_6_3_, protocol0_.created_by as created_2_2_0_, protocol0_.created_date as created_3_2_0_, protocol0_.description as descript4_2_0_, protocol0_.index_def_id as index_de8_2_0_, protocol0_.generate_info_id as generate9_2_0_, protocol0_.modified_by as modified5_2_0_, protocol0_.modified_date as modified6_2_0_, protocol0_.name as name7_2_0_, inclusionr3_.protocol_id as protocol1_2_0__, inclusionr3_.description as descript2_1_0__, inclusionr3_.expression as expressi3_1_0__, inclusionr3_.name as name4_1_0__, inclusionr3_.sequence as sequence5_0__, cohortdefi1_.created_by as created_2_3_1_, cohortdefi1_.created_date as created_3_3_1_, cohortdefi1_.description as descript4_3_1_, cohortdefi1_.expression_type as expressi5_3_1_, cohortdefi1_.modified_by as modified6_3_1_, cohortdefi1_.modified_date as modified7_3_1_, cohortdefi1_.name as name8_3_1_, inclusionr3_.protocol_id as protocol1_2_0__, inclusionr3_.description as descript2_1_0__, inclusionr3_.expression as expressi3_1_0__, inclusionr3_.name as name4_1_0__, inclusionr3_.sequence as sequence5_0__, cohortdefi2_.expression as expressi2_4_2_, inclusionr3_.protocol_id as protocol1_2_0__, inclusionr3_.description as descript2_1_0__, inclusionr3_.expression as expressi3_1_0__, inclusionr3_.name as name4_1_0__, inclusionr3_.sequence as sequence5_0__, simulation4_.execution_duration as executio2_6_3_, simulation4_.is_valid as is_valid3_6_3_, simulation4_.start_time as start_ti4_6_3_, simulation4_.status as status5_6_3_
from clinical_trial_protocol protocol0_
left outer join cohort_definition cohortdefi1_ on protocol0_.index_def_id=cohortdefi1_.id
left outer join cohort_definition_details cohortdefi2_ on cohortdefi1_.id=cohortdefi2_.id
cross join left outer join clinical_trial_inclusion inclusionr3_ on protocol0_.id=inclusionr3_.protocol_id left outer join simulation_generation_info simulation4_ on protocol0_.generate_info_id=simulation4_.id where protocol0_.id=17
select protocol0_.id as id1_2_0_, simulation2_.id as id1_6_1_, cohortdefi3_.id as id1_3_2_, cohortdefi4_.id as id1_4_3_, protocol0_.created_by as created_2_2_0_, protocol0_.created_date as created_3_2_0_, protocol0_.description as descript4_2_0_, protocol0_.index_def_id as index_de8_2_0_, protocol0_.generate_info_id as generate9_2_0_, protocol0_.modified_by as modified5_2_0_, protocol0_.modified_date as modified6_2_0_, protocol0_.name as name7_2_0_, inclusionr1_.protocol_id as protocol1_2_0__, inclusionr1_.description as descript2_1_0__, inclusionr1_.expression as expressi3_1_0__, inclusionr1_.name as name4_1_0__, inclusionr1_.sequence as sequence5_0__, simulation2_.execution_duration as executio2_6_1_, simulation2_.is_valid as is_valid3_6_1_, simulation2_.start_time as start_ti4_6_1_, simulation2_.status as status5_6_1_, cohortdefi3_.created_by as created_2_3_2_, cohortdefi3_.created_date as created_3_3_2_, cohortdefi3_.description as descript4_3_2_, cohortdefi3_.expression_type as expressi5_3_2_, cohortdefi3_.modified_by as modified6_3_2_, cohortdefi3_.modified_date as modified7_3_2_, cohortdefi3_.name as name8_3_2_, cohortdefi4_.expression as expressi2_4_3_
from clinical_trial_protocol protocol0_
left outer join clinical_trial_inclusion inclusionr1_ on protocol0_.id=inclusionr1_.protocol_id
left outer join simulation_generation_info simulation2_ on protocol0_.generate_info_id=simulation2_.id
left outer join cohort_definition cohortdefi3_ on protocol0_.index_def_id=cohortdefi3_.id
left outer join cohort_definition_details cohortdefi4_ on cohortdefi3_.id=cohortdefi4_.id where protocol0_.id=17
The problem is this ‘cross left join outer join’ at the end of the first query. I"m not sure why I’m getting different results: the war file is bundled with the correct hibernate library…from all of the logs, it appears that the runtime is identical (hibernate finds the same dialects formt he same connection strings), the database is even the same!
So, I just wanted to put this out there for other people that may be seeing the same problem. Don’t trust your local environment, and always sanity check against an environment that mirrors your production environment.
-Chris