1 | public void testComponentPropertyRef() {↵ | | 1 | public void testComponentPropertyRef() {↵
|
2 | Person p = new Person();↵ | | 2 | Person p = new Person();↵
|
3 | p.setIdentity( new Identity() );↵ | | 3 | p.setIdentity( new Identity() );↵
|
4 | Account a = new Account();↵ | | 4 | Account a = new Account();↵
|
5 | a.setNumber("123-12345-1236");↵ | | 5 | a.setNumber("123-12345-1236");↵
|
6 | a.setOwner(p);↵ | | 6 | a.setOwner(p);↵
|
7 | p.getIdentity().setName("Gavin");↵ | | 7 | p.getIdentity().setName("Gavin");↵
|
8 | p.getIdentity().setSsn("123-12-1234");↵ | | 8 | p.getIdentity().setSsn("123-12-1234");↵
|
9 | Session s = openSession();↵ | | 9 | Session s = openSession();↵
|
10 | Transaction tx = s.beginTransaction();↵ | | 10 | Transaction tx = s.beginTransaction();↵
|
11 | s.persist(p);↵ | | 11 | s.persist(p);↵
|
12 | s.persist(a);↵ | | 12 | s.persist(a);↵
|
13 | s.flush();↵ | | 13 | s.flush();↵
|
14 | s.clear();↵ | | 14 | s.clear();↵
|
| | | 15 | ↵
|
15 | a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();↵ | | 16 | a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();↵
|
16 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 17 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
17 | assertNotNull( a.getOwner() );↵ | | 18 | assertNotNull( a.getOwner() );↵
|
18 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 19 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
19 | s.clear();↵ | | 20 | s.clear();↵
|
| | | 21 | ↵
|
20 | a = (Account) s.get(Account.class, "123-12345-1236");↵ | | 22 | a = (Account) s.get(Account.class, "123-12345-1236");↵
|
21 | assertFalse( Hibernate.isInitialized( a.getOwner() ) );↵ | | 23 | assertFalse( Hibernate.isInitialized( a.getOwner() ) );↵
|
22 | assertNotNull( a.getOwner() );↵ | | 24 | assertNotNull( a.getOwner() );↵
|
23 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 25 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
24 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 26 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
| | | 27 | ↵
|
25 | s.clear();↵ | | 28 | s.clear();↵
|
| | | 29 | ↵
|
26 | getSessions().evict(Account.class);↵ | | 30 | getSessions().evict(Account.class);↵
|
27 | getSessions().evict(Person.class);↵ | | 31 | getSessions().evict(Person.class);↵
|
| | | 32 | ↵
|
28 | a = (Account) s.get(Account.class, "123-12345-1236");↵ | | 33 | a = (Account) s.get(Account.class, "123-12345-1236");↵
|
29 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 34 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
30 | assertNotNull( a.getOwner() );↵ | | 35 | assertNotNull( a.getOwner() );↵
|
31 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 36 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
32 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 37 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
| | | 38 | ↵
|
33 | s.delete( a );↵ | | 39 | s.delete( a );↵
|
34 | s.delete( a.getOwner() );↵ | | 40 | s.delete( a.getOwner() );↵
|
35 | tx.commit();↵ | | 41 | tx.commit();↵
|
36 | s.close();↵ | | 42 | s.close();↵
|
37 | | | 43 |
|