KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > subclasspropertyref > SubclassPropertyRefTest


1 //$Id: SubclassPropertyRefTest.java,v 1.1 2005/03/06 16:34:02 oneovthafew Exp $
2
package org.hibernate.test.subclasspropertyref;
3
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.hibernate.Hibernate;
8 import org.hibernate.Session;
9 import org.hibernate.Transaction;
10 import org.hibernate.test.TestCase;
11
12 /**
13  * @author Gavin King
14  */

15 public class SubclassPropertyRefTest extends TestCase {
16     
17     public SubclassPropertyRefTest(String JavaDoc str) {
18         super(str);
19     }
20     
21     public void testOneToOnePropertyRef() {
22         Session s = openSession();
23         Transaction t = s.beginTransaction();
24         Customer c = new Customer();
25         c.setName("Emmanuel");
26         c.setCustomerId("C123-456");
27         c.setPersonId("P123-456");
28         Account a = new Account();
29         a.setCustomer(c);
30         a.setPerson(c);
31         a.setType('X');
32         s.persist(c);
33         s.persist(a);
34         t.commit();
35         s.close();
36         
37         s = openSession();
38         t = s.beginTransaction();
39         a = (Account) s.createQuery("from Account acc join fetch acc.customer join fetch acc.person").uniqueResult();
40         assertNotNull( a.getCustomer() );
41         assertTrue( Hibernate.isInitialized( a.getCustomer() ) );
42         assertNotNull( a.getPerson() );
43         assertTrue( Hibernate.isInitialized( a.getPerson() ) );
44         c = (Customer) s.createQuery("from Customer").uniqueResult();
45         assertSame( c, a.getCustomer() );
46         assertSame( c, a.getPerson() );
47         s.delete(a);
48         s.delete( a.getCustomer() );
49         s.delete( a.getPerson() );
50         t.commit();
51         s.close();
52     }
53
54     
55     protected String JavaDoc[] getMappings() {
56         return new String JavaDoc[] { "subclasspropertyref/Person.hbm.xml" };
57     }
58
59     public static Test suite() {
60         return new TestSuite(SubclassPropertyRefTest.class);
61     }
62
63 }
64
65
Popular Tags