I tried this:
Code:
@Test
public void testCollection() {
formItem0 = new FormItem();
formItem0.setName("name");
formItem0.setListOrder(2);
formItem0.setType("itemtype");
formItem0.setForm(form0);
formItem1 = new FormItem();
formItem1.setName("name");
formItem1.setListOrder(1);
formItem1.setType("itemtype");
formItem1.setForm(form0);
form0 = formDao.makePersistent(form0);
formItem0 = formItemDao.makePersistent(formItem0);
formItem1 = formItemDao.makePersistent(formItem1);
Form retrievedForm = formDao.findById(form0.getId(), false);
assertEquals(2, retrievedForm.getFormItems().size());
}
with Hibernate sending the following (that look okay to me) sql statements:
Quote:
Hibernate:
insert
into
form
(version, name, id)
values
(?, ?, null)
19:19:09,198 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:19:09,198 DEBUG StringType:133 - binding 'form0' to parameter: 2
Hibernate:
call identity()
Hibernate:
insert
into
form_item
(version, form_id, type, name, list_order, id)
values
(?, ?, ?, ?, ?, null)
19:19:09,199 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:19:09,200 DEBUG IntegerType:133 - binding '6' to parameter: 2
19:19:09,200 DEBUG StringType:133 - binding 'itemtype' to parameter: 3
19:19:09,200 DEBUG StringType:133 - binding 'name' to parameter: 4
19:19:09,201 DEBUG IntegerType:133 - binding '2' to parameter: 5
Hibernate:
call identity()
Hibernate:
insert
into
form_item
(version, form_id, type, name, list_order, id)
values
(?, ?, ?, ?, ?, null)
19:19:09,202 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:19:09,203 DEBUG IntegerType:133 - binding '6' to parameter: 2
19:19:09,203 DEBUG StringType:133 - binding 'itemtype' to parameter: 3
19:19:09,203 DEBUG StringType:133 - binding 'name' to parameter: 4
19:19:09,203 DEBUG IntegerType:133 - binding '1' to parameter: 5
Hibernate:
call identity()
19:19:09,205 INFO TransactionalTestExecutionListener:279 - Rolled back transaction after test execution for test context [[TestContext@164de59 testClass = FormDaoTest, locations = array<String>['classpath:spring-hibernate.xml', 'classpath:spring-hibernate-dao.xml', 'classpath:spring-data-source.xml'], testInstance = com.thalasoft.learnintouch.core.dao.FormDaoTest@98f352, testMethod = testCollection@FormDaoTest, testException = java.lang.AssertionError: expected:<2> but was:<0>]]
org.apache.maven.surefire.booter.SurefireExecutionException: org/junit/Assume$AssumptionViolatedException; nested exception is java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
and this
Code:
@Test
public void testCollection() {
formItem0 = new FormItem();
formItem0.setName("name");
formItem0.setListOrder(2);
formItem0.setType("itemtype");
formItem0.setForm(form0);
formItem1 = new FormItem();
formItem1.setName("name");
formItem1.setListOrder(1);
formItem1.setType("itemtype");
formItem1.setForm(form0);
formItem0 = formItemDao.makePersistent(formItem0);
formItem1 = formItemDao.makePersistent(formItem1);
form0 = formDao.makePersistent(form0);
Form retrievedForm = formDao.findById(form0.getId(), false);
assertEquals(2, retrievedForm.getFormItems().size());
}
with Hibernate sending the following (and apparently the same) sql statements:
Quote:
Hibernate:
insert
into
form
(version, name, id)
values
(?, ?, null)
19:21:48,585 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:21:48,586 DEBUG StringType:133 - binding 'form0' to parameter: 2
Hibernate:
call identity()
Hibernate:
insert
into
form_item
(version, form_id, type, name, list_order, id)
values
(?, ?, ?, ?, ?, null)
19:21:48,587 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:21:48,588 DEBUG IntegerType:133 - binding '6' to parameter: 2
19:21:48,588 DEBUG StringType:133 - binding 'itemtype' to parameter: 3
19:21:48,588 DEBUG StringType:133 - binding 'name' to parameter: 4
19:21:48,588 DEBUG IntegerType:133 - binding '2' to parameter: 5
Hibernate:
call identity()
Hibernate:
insert
into
form_item
(version, form_id, type, name, list_order, id)
values
(?, ?, ?, ?, ?, null)
19:21:48,589 DEBUG IntegerType:133 - binding '0' to parameter: 1
19:21:48,589 DEBUG IntegerType:133 - binding '6' to parameter: 2
19:21:48,590 DEBUG StringType:133 - binding 'itemtype' to parameter: 3
19:21:48,590 DEBUG StringType:133 - binding 'name' to parameter: 4
19:21:48,590 DEBUG IntegerType:133 - binding '1' to parameter: 5
Hibernate:
call identity()
19:21:48,592 INFO TransactionalTestExecutionListener:279 - Rolled back transaction after test execution for test context [[TestContext@10e8647 testClass = FormDaoTest, locations = array<String>['classpath:spring-hibernate.xml', 'classpath:spring-hibernate-dao.xml', 'classpath:spring-data-source.xml'], testInstance = com.thalasoft.learnintouch.core.dao.FormDaoTest@1bb205a, testMethod = testCollection@FormDaoTest, testException = java.lang.AssertionError: expected:<2> but was:<0>]]
org.apache.maven.surefire.booter.SurefireExecutionException: org/junit/Assume$AssumptionViolatedException; nested exception is java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)