From e6862c0be0b8eda6c8211ec2a12c68eafb418cf0 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Fri, 18 Jun 2010 16:40:00 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19766 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../annotations/onetomany/OneToManyTest.java | 24 ++++++++++++++++++- .../test/annotations/onetomany/Trainer.java | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java b/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java index fd0a9be3bd..b458e51b5a 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java @@ -6,6 +6,7 @@ import java.util.Collection; 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 @@ public class OneToManyTest extends TestCase { assertNotNull( trainer ); assertNotNull( trainer.getTrainedMonkeys() ); assertEquals( 2, trainer.getTrainedMonkeys().size() ); - tx.rollback(); + + //test suppression of trainer wo monkey + final Set 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(); } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java b/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java index 20482fc98a..4672e67340 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/onetomany/Trainer.java @@ -53,7 +53,8 @@ public class Trainer { @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")