1 | public void testOneToOnePropertyRef() {↵ | | 1 | public void testOneToOnePropertyRef() {↵
|
2 | Session s = openSession();↵ | | 2 | Session s = openSession();↵
|
3 | Transaction t = s.beginTransaction();↵ | | 3 | Transaction t = s.beginTransaction();↵
|
4 | Customer c = new Customer();↵ | | 4 | Customer c = new Customer();↵
|
5 | c.setName( "Emmanuel" );↵ | | 5 | c.setName( "Emmanuel" );↵
|
6 | c.setCustomerId( "C123-456" );↵ | | 6 | c.setCustomerId( "C123-456" );↵
|
7 | c.setPersonId( "P123-456" );↵ | | 7 | c.setPersonId( "P123-456" );↵
|
8 | Account a = new Account();↵ | | 8 | Account a = new Account();↵
|
9 | a.setCustomer( c );↵ | | 9 | a.setCustomer( c );↵
|
10 | a.setPerson( c );↵ | | 10 | a.setPerson( c );↵
|
11 | a.setType( 'X' );↵ | | 11 | a.setType( 'X' );↵
|
12 | s.persist( c );↵ | | 12 | s.persist( c );↵
|
13 | s.persist( a );↵ | | 13 | s.persist( a );↵
|
14 | t.commit();↵ | | 14 | t.commit();↵
|
15 | s.close();↵ | | 15 | s.close();↵
|
|
16 | s = openSession();↵ | | 16 | s = openSession();↵
|
17 | t = s.beginTransaction();↵ | | 17 | t = s.beginTransaction();↵
|
18 | a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join fetch acc.person" )↵ | | 18 | a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join fetch acc.person" )↵
|
19 | .uniqueResult();↵ | | 19 | .uniqueResult();↵
|
20 | assertNotNull( a.getCustomer() );↵ | | 20 | assertNotNull( a.getCustomer() );↵
|
21 | assertTrue( Hibernate.isInitialized( a.getCustomer() ) );↵ | | 21 | assertTrue( Hibernate.isInitialized( a.getCustomer() ) );↵
|
22 | assertNotNull( a.getPerson() );↵ | | 22 | assertNotNull( a.getPerson() );↵
|
23 | assertTrue( Hibernate.isInitialized( a.getPerson() ) );↵ | | 23 | assertTrue( Hibernate.isInitialized( a.getPerson() ) );↵
|
24 | c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();↵ | | 24 | c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();↵
|
25 | assertSame( c, a.getCustomer() );↵ | | 25 | assertSame( c, a.getCustomer() );↵
|
26 | assertSame( c, a.getPerson() );↵ | | 26 | assertSame( c, a.getPerson() );↵
|
27 | s.delete( a );↵ | | 27 | s.delete( a );↵
|
28 | s.delete( a.getCustomer() );↵ | | 28 | s.delete( a.getCustomer() );↵
|
29 | s.delete( a.getPerson() );↵ | | 29 | s.delete( a.getPerson() );↵
|
30 | t.commit();↵ | | 30 | t.commit();↵
|
31 | s.close();↵ | | 31 | s.close();↵
|
32 | | | 32 |
|