~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.test.propertyref.inheritence.union;
 
2
 
 
3
import junit.framework.Test;
 
4
 
 
5
import org.hibernate.Hibernate;
 
6
import org.hibernate.Session;
 
7
import org.hibernate.Transaction;
 
8
import org.hibernate.junit.functional.FunctionalTestCase;
 
9
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
10
 
 
11
/**
 
12
 * @author Gavin King
 
13
 */
 
14
public class UnionSubclassPropertyRefTest extends FunctionalTestCase {
 
15
 
 
16
        public UnionSubclassPropertyRefTest(String name) {
 
17
                super( name );
 
18
        }
 
19
 
 
20
        public String[] getMappings() {
 
21
                return new String[] { "propertyref/inheritence/union/Person.hbm.xml" };
 
22
        }
 
23
 
 
24
        public static Test suite() {
 
25
                return new FunctionalTestClassTestSuite( UnionSubclassPropertyRefTest.class );
 
26
        }
 
27
 
 
28
        public void testOneToOnePropertyRef() {
 
29
                Session s = openSession();
 
30
                Transaction t = s.beginTransaction();
 
31
                Customer c = new Customer();
 
32
                c.setName( "Emmanuel" );
 
33
                c.setCustomerId( "C123-456" );
 
34
                c.setPersonId( "P123-456" );
 
35
                Account a = new Account();
 
36
                a.setCustomer( c );
 
37
                a.setPerson( c );
 
38
                a.setType( 'X' );
 
39
                s.persist( c );
 
40
                s.persist( a );
 
41
                t.commit();
 
42
                s.close();
 
43
 
 
44
                s = openSession();
 
45
                t = s.beginTransaction();
 
46
                a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join fetch acc.person" )
 
47
                                .uniqueResult();
 
48
                assertNotNull( a.getCustomer() );
 
49
                assertTrue( Hibernate.isInitialized( a.getCustomer() ) );
 
50
                assertNotNull( a.getPerson() );
 
51
                assertTrue( Hibernate.isInitialized( a.getPerson() ) );
 
52
                c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();
 
53
                assertSame( c, a.getCustomer() );
 
54
                assertSame( c, a.getPerson() );
 
55
                s.delete( a );
 
56
                s.delete( a.getCustomer() );
 
57
                s.delete( a.getPerson() );
 
58
                t.commit();
 
59
                s.close();
 
60
        }
 
61
 
 
62
}