1 | public class SubclassPropertyRefTest extends FunctionalTestCase {↵ | | 1 | public class UnionSubclassPropertyRefTest extends FunctionalTestCase {↵
|
|
2 | public SubclassPropertyRefTest(String name) {↵ | | 2 | public UnionSubclassPropertyRefTest(String name) {↵
|
3 | super( name );↵ | | 3 | super( name );↵
|
4 | }↵ | | 4 | }↵
|
|
5 | public String[] getMappings() {↵ | | 5 | public String[] getMappings() {↵
|
6 | return new String[] { "propertyref/inheritence/discrim/Person.hbm.xml" };↵ | | 6 | return new String[] { "propertyref/inheritence/union/Person.hbm.xml" };↵
|
7 | }↵ | | 7 | }↵
|
|
8 | public static Test suite() {↵ | | 8 | public static Test suite() {↵
|
9 | return new FunctionalTestClassTestSuite( SubclassPropertyRefTest.class );↵ | | 9 | return new FunctionalTestClassTestSuite( UnionSubclassPropertyRefTest.class );↵
|
10 | }↵ | | 10 | }↵
|
|
11 | public void testOneToOnePropertyRef() {↵ | | 11 | public void testOneToOnePropertyRef() {↵
|
12 | Session s = openSession();↵ | | 12 | Session s = openSession();↵
|
13 | Transaction t = s.beginTransaction();↵ | | 13 | Transaction t = s.beginTransaction();↵
|
14 | Customer c = new Customer();↵ | | 14 | Customer c = new Customer();↵
|
15 | c.setName( "Emmanuel" );↵ | | 15 | c.setName( "Emmanuel" );↵
|
16 | c.setCustomerId( "C123-456" );↵ | | 16 | c.setCustomerId( "C123-456" );↵
|
17 | c.setPersonId( "P123-456" );↵ | | 17 | c.setPersonId( "P123-456" );↵
|
18 | Account a = new Account();↵ | | 18 | Account a = new Account();↵
|
19 | a.setCustomer( c );↵ | | 19 | a.setCustomer( c );↵
|
20 | a.setPerson( c );↵ | | 20 | a.setPerson( c );↵
|
21 | a.setType( 'X' );↵ | | 21 | a.setType( 'X' );↵
|
22 | s.persist( c );↵ | | 22 | s.persist( c );↵
|
23 | s.persist( a );↵ | | 23 | s.persist( a );↵
|
24 | t.commit();↵ | | 24 | t.commit();↵
|
25 | s.close();↵ | | 25 | s.close();↵
|
|
26 | s = openSession();↵ | | 26 | s = openSession();↵
|
27 | t = s.beginTransaction();↵ | | 27 | t = s.beginTransaction();↵
|
28 | a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join fetch acc.person" )↵ | | 28 | a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join fetch acc.person" )↵
|
29 | .uniqueResult();↵ | | 29 | .uniqueResult();↵
|
30 | assertNotNull( a.getCustomer() );↵ | | 30 | assertNotNull( a.getCustomer() );↵
|
31 | assertTrue( Hibernate.isInitialized( a.getCustomer() ) );↵ | | 31 | assertTrue( Hibernate.isInitialized( a.getCustomer() ) );↵
|
32 | assertNotNull( a.getPerson() );↵ | | 32 | assertNotNull( a.getPerson() );↵
|
33 | assertTrue( Hibernate.isInitialized( a.getPerson() ) );↵ | | 33 | assertTrue( Hibernate.isInitialized( a.getPerson() ) );↵
|
34 | c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();↵ | | 34 | c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();↵
|
35 | assertSame( c, a.getCustomer() );↵ | | 35 | assertSame( c, a.getCustomer() );↵
|
36 | assertSame( c, a.getPerson() );↵ | | 36 | assertSame( c, a.getPerson() );↵
|
37 | s.delete( a );↵ | | 37 | s.delete( a );↵
|
38 | s.delete( a.getCustomer() );↵ | | 38 | s.delete( a.getCustomer() );↵
|
39 | s.delete( a.getPerson() );↵ | | 39 | s.delete( a.getPerson() );↵
|
40 | t.commit();↵ | | 40 | t.commit();↵
|
41 | s.close() | | 41 | s.close()
|