1 | public class CompleteComponentPropertyRefTest extends FunctionalTestCase {↵ | | 1 | public class PartialComponentPropertyRefTest extends FunctionalTestCase {↵
|
| | | 2 | ↵
|
2 | public CompleteComponentPropertyRefTest(String name) {↵ | | 3 | public PartialComponentPropertyRefTest(String name) {↵
|
3 | super( name );↵ | | 4 | super( name );↵
|
4 | }↵ | | 5 | }↵
|
|
5 | public String[] getMappings() {↵ | | 6 | public String[] getMappings() {↵
|
6 | return new String[] { "propertyref/component/complete/Mapping.hbm.xml" };↵ | | 7 | return new String[] { "propertyref/component/partial/Mapping.hbm.xml" };↵
|
7 | }↵ | | 8 | }↵
|
|
8 | public static Test suite() {↵ | | 9 | public static Test suite() {↵
|
9 | return new FunctionalTestClassTestSuite( CompleteComponentPropertyRefTest.class );↵ | | 10 | return new FunctionalTestClassTestSuite( PartialComponentPropertyRefTest.class );↵
|
10 | }↵ | | 11 | }↵
|
| | | 12 | ↵
|
11 | public void testComponentPropertyRef() {↵ | | 13 | public void testComponentPropertyRef() {↵
|
12 | Person p = new Person();↵ | | 14 | Person p = new Person();↵
|
13 | p.setIdentity( new Identity() );↵ | | 15 | p.setIdentity( new Identity() );↵
|
14 | Account a = new Account();↵ | | 16 | Account a = new Account();↵
|
15 | a.setNumber("123-12345-1236");↵ | | 17 | a.setNumber("123-12345-1236");↵
|
16 | a.setOwner(p);↵ | | 18 | a.setOwner(p);↵
|
17 | p.getIdentity().setName("Gavin");↵ | | 19 | p.getIdentity().setName("Gavin");↵
|
18 | p.getIdentity().setSsn("123-12-1234");↵ | | 20 | p.getIdentity().setSsn("123-12-1234");↵
|
19 | Session s = openSession();↵ | | 21 | Session s = openSession();↵
|
20 | Transaction tx = s.beginTransaction();↵ | | 22 | Transaction tx = s.beginTransaction();↵
|
21 | s.persist(p);↵ | | 23 | s.persist(p);↵
|
22 | s.persist(a);↵ | | 24 | s.persist(a);↵
|
23 | s.flush();↵ | | 25 | s.flush();↵
|
24 | s.clear();↵ | | 26 | s.clear();↵
|
| | | 27 | ↵
|
25 | a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();↵ | | 28 | a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();↵
|
26 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 29 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
27 | assertNotNull( a.getOwner() );↵ | | 30 | assertNotNull( a.getOwner() );↵
|
28 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 31 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
29 | s.clear();↵ | | 32 | s.clear();↵
|
| | | 33 | ↵
|
30 | a = (Account) s.get(Account.class, "123-12345-1236");↵ | | 34 | a = (Account) s.get(Account.class, "123-12345-1236");↵
|
31 | assertFalse( Hibernate.isInitialized( a.getOwner() ) );↵ | | 35 | assertFalse( Hibernate.isInitialized( a.getOwner() ) );↵
|
32 | assertNotNull( a.getOwner() );↵ | | 36 | assertNotNull( a.getOwner() );↵
|
33 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 37 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
34 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 38 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
| | | 39 | ↵
|
35 | s.clear();↵ | | 40 | s.clear();↵
|
| | | 41 | ↵
|
36 | getSessions().evict(Account.class);↵ | | 42 | getSessions().evict(Account.class);↵
|
37 | getSessions().evict(Person.class);↵ | | 43 | getSessions().evict(Person.class);↵
|
| | | 44 | ↵
|
38 | a = (Account) s.get(Account.class, "123-12345-1236");↵ | | 45 | a = (Account) s.get(Account.class, "123-12345-1236");↵
|
39 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 46 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
40 | assertNotNull( a.getOwner() );↵ | | 47 | assertNotNull( a.getOwner() );↵
|
41 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵ | | 48 | assertEquals( "Gavin", a.getOwner().getIdentity().getName() );↵
|
42 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵ | | 49 | assertTrue( Hibernate.isInitialized( a.getOwner() ) );↵
|
| | | 50 | ↵
|
43 | s.delete( a );↵ | | 51 | s.delete( a );↵
|
44 | s.delete( a.getOwner() );↵ | | 52 | s.delete( a.getOwner() );↵
|
45 | tx.commit();↵ | | 53 | tx.commit();↵
|
46 | s.close() | | 54 | s.close()
|