Ok, so I've made my situation work, but it leads me to another question about Hibernate and flushing sessions (I think).
For clarity's sake, I created two classes. TestModelClass has a List of TestModelClass2. TestModelClass2 has two String fields. I am using Criteria queries and QBE to search for TestModelClass giving only an example of TestModelClass2 with one String field filled in.
I was running a test case and persisting the test objects and searching within the same transaction. This was the SQL that hibernate listed:
10:32:30,640 DEBUG SQL:393 - insert into TestModelClass2 (version, string1, string2) values (?, ?, ?)
10:32:30,671 DEBUG SQL:393 - insert into TestModelClass2 (version, string1, string2) values (?, ?, ?)
10:32:30,687 DEBUG SQL:393 - insert into TestModelClass (version) values (?)
10:32:30,843 DEBUG SQL:393 - select this_.id as id25_1_, this_.version as version25_1_, member3_.TestModelClass_id as TestMode1_, testmodelc1_.id as member2_, testmodelc1_.id as id26_0_, testmodelc1_.version as version26_0_, testmodelc1_.string1 as string3_26_0_, testmodelc1_.string2 as string4_26_0_ from TestModelClass this_ inner join TestModelClass_TestModelClass2 member3_ on this_.id=member3_.TestModelClass_id inner join TestModelClass2 testmodelc1_ on member3_.member_id=testmodelc1_.id where (1=1) and (testmodelc1_.string1=?)
Conspicuously missing are the lines updating the List<TestModelClass2> relation.
I ran the tests again, this time committing the transaction where I persisted my test objects and starting a new transaction for the search. Here is that output:
10:32:30,640 DEBUG SQL:393 - insert into TestModelClass2 (version, string1, string2) values (?, ?, ?)
10:32:30,671 DEBUG SQL:393 - insert into TestModelClass2 (version, string1, string2) values (?, ?, ?)
10:32:30,687 DEBUG SQL:393 - insert into TestModelClass (version) values (?)
10:32:30,718 DEBUG SQL:393 - insert into TestModelClass_TestModelClass2 (TestModelClass_id, member_id) values (?, ?)
10:32:30,718 DEBUG SQL:393 - insert into TestModelClass_TestModelClass2 (TestModelClass_id, member_id) values (?, ?)
10:32:30,843 DEBUG SQL:393 - select this_.id as id25_1_, this_.version as version25_1_, member3_.TestModelClass_id as TestMode1_, testmodelc1_.id as member2_, testmodelc1_.id as id26_0_, testmodelc1_.version as version26_0_, testmodelc1_.string1 as string3_26_0_, testmodelc1_.string2 as string4_26_0_ from TestModelClass this_ inner join TestModelClass_TestModelClass2 member3_ on this_.id=member3_.TestModelClass_id inner join TestModelClass2 testmodelc1_ on member3_.member_id=testmodelc1_.id where (1=1) and (testmodelc1_.string1=?)
Why did I not get thsoe two lines showing my list was saved the first time? This is fairly annoying because its nice to run test cases without changing the database.
|