FileDocCategorySizeDatePackage
JoinedSubclassPropertyRefTest.javaAPI DocHibernate 3.2.51930Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.propertyref.inheritence.joined

JoinedSubclassPropertyRefTest

public class JoinedSubclassPropertyRefTest extends org.hibernate.junit.functional.FunctionalTestCase
author
Gavin King

Fields Summary
Constructors Summary
public JoinedSubclassPropertyRefTest(String name)

		super( name );
	
Methods Summary
public java.lang.String[]getMappings()

		return new String[] { "propertyref/inheritence/joined/Person.hbm.xml" };
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( JoinedSubclassPropertyRefTest.class );
	
public voidtestPropertyRefToJoinedSubclass()

		Session session = openSession();
		Transaction tx = session.beginTransaction();
		Person p = new Person();
		p.setName("Gavin King");
		BankAccount acc = new BankAccount();
		acc.setBsb("0634");
		acc.setType('B");
		acc.setAccountNumber("xxx-123-abc");
		p.setBankAccount(acc);
		session.persist(p);
		tx.commit();
		session.close();

		session = openSession();
		tx = session.beginTransaction();
		p = (Person) session.get(Person.class, p.getId());
		assertNotNull( p.getBankAccount() );
		assertTrue( Hibernate.isInitialized( p.getBankAccount() ) );
		tx.commit();
		session.close();

		session = openSession();
		tx = session.beginTransaction();
		p = (Person) session.createCriteria(Person.class)
			.setFetchMode("bankAccount", FetchMode.JOIN)
			.uniqueResult();
		assertNotNull( p.getBankAccount() );
		assertTrue( Hibernate.isInitialized( p.getBankAccount() ) );
		tx.commit();
		session.close();

		session = openSession();
		tx = session.beginTransaction();
		session.delete(p);
		tx.commit();
		session.close();