[hibernate-commits] Hibernate SVN: r19767 - core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jun 18 12:50:21 EDT 2010
Author: epbernard
Date: 2010-06-18 12:50:20 -0400 (Fri, 18 Jun 2010)
New Revision: 19767
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java
Log:
HHH-5319 Add more tests on @OneToMany @JoinTable unidirectional
In particular, test delete of the owning object wo the associated objects
and clean up properly after the test.
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2010-06-18 16:40:00 UTC (rev 19766)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2010-06-18 16:50:20 UTC (rev 19767)
@@ -6,6 +6,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -172,7 +173,28 @@
assertNotNull( trainer );
assertNotNull( trainer.getTrainedMonkeys() );
assertEquals( 2, trainer.getTrainedMonkeys().size() );
- tx.rollback();
+
+ //test suppression of trainer wo monkey
+ final Set<Monkey> monkeySet = new HashSet( trainer.getTrainedMonkeys() );
+ s.delete( trainer );
+ s.flush();
+ tx.commit();
+
+ s.clear();
+
+ tx = s.beginTransaction();
+ for ( Monkey m : monkeySet ) {
+ final Object managedMonkey = s.get( Monkey.class, m.getId() );
+ assertNotNull( "No trainers but monkeys should still be here", managedMonkey );
+ }
+
+ //clean up
+ for ( Monkey m : monkeySet ) {
+ final Object managedMonkey = s.get( Monkey.class, m.getId() );
+ s.delete(managedMonkey);
+ }
+ s.flush();
+ tx.commit();
s.close();
}
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java 2010-06-18 16:40:00 UTC (rev 19766)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java 2010-06-18 16:50:20 UTC (rev 19767)
@@ -53,7 +53,8 @@
@OneToMany
@JoinTable(
name = "TrainedMonkeys",
- joinColumns = {@JoinColumn(name = "trainer_id")},
+ //columns are optional, here we explicit them
+ joinColumns = @JoinColumn(name = "trainer_id"),
inverseJoinColumns = @JoinColumn(name = "monkey_id")
)
@ForeignKey(name = "TM_TRA_FK", inverseName = "TM_MON_FK")
More information about the hibernate-commits
mailing list