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
This commit is contained in:
parent
7e9ddb926a
commit
e6862c0be0
|
@ -6,6 +6,7 @@ import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
@ -172,7 +173,28 @@ public class OneToManyTest extends TestCase {
|
||||||
assertNotNull( trainer );
|
assertNotNull( trainer );
|
||||||
assertNotNull( trainer.getTrainedMonkeys() );
|
assertNotNull( trainer.getTrainedMonkeys() );
|
||||||
assertEquals( 2, trainer.getTrainedMonkeys().size() );
|
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();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ public class Trainer {
|
||||||
@OneToMany
|
@OneToMany
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "TrainedMonkeys",
|
name = "TrainedMonkeys",
|
||||||
joinColumns = {@JoinColumn(name = "trainer_id")},
|
//columns are optional, here we explicit them
|
||||||
|
joinColumns = @JoinColumn(name = "trainer_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "monkey_id")
|
inverseJoinColumns = @JoinColumn(name = "monkey_id")
|
||||||
)
|
)
|
||||||
@ForeignKey(name = "TM_TRA_FK", inverseName = "TM_MON_FK")
|
@ForeignKey(name = "TM_TRA_FK", inverseName = "TM_MON_FK")
|
||||||
|
|
Loading…
Reference in New Issue