Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 09:37:32 -0500 (Tue, 05 Dec 2006)
New Revision: 10920
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java
Removed:
trunk/Hibernate3/test/org/hibernate/test/comppropertyref/
trunk/Hibernate3/test/org/hibernate/test/joineduid/
trunk/Hibernate3/test/org/hibernate/test/propertyref/Account.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/Address.java
trunk/Hibernate3/test/org/hibernate/test/subclasspropertyref/
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
trunk/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2282 : PersistentClass propetty lookups and embedded composite identifiers;
consolidate property-ref tests
Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-12-05 14:35:29 UTC (rev
10919)
+++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-12-05 14:37:32 UTC (rev
10920)
@@ -2397,7 +2397,7 @@
keyVal = collection.getOwner().getIdentifier();
}
else {
- keyVal = (KeyValue) collection.getOwner().getProperty( propRef ).getValue();
+ keyVal = (KeyValue) collection.getOwner().getRecursiveProperty( propRef
).getValue();
}
SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal );
key.setCascadeDeleteEnabled( "cascade"
Modified: trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 14:35:29
UTC (rev 10919)
+++ trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 14:37:32
UTC (rev 10920)
@@ -310,71 +310,85 @@
public void setSelectBeforeUpdate(boolean selectBeforeUpdate) {
this.selectBeforeUpdate = selectBeforeUpdate;
}
-
+
+ /**
+ * Build an iterator of properties which are "referenceable".
+ *
+ * @see #getReferencedProperty for a discussion of "referenceable"
+ * @return The property iterator.
+ */
public Iterator getReferenceablePropertyIterator() {
return getPropertyClosureIterator();
}
+ /**
+ * Given a property path, locate the appropriate referenceable property reference.
+ * <p/>
+ * A referenceable property is a property which can be a target of a foreign-key
+ * mapping (an identifier or explcitly named in a property-ref).
+ *
+ * @param propertyPath The property path to resolve into a property reference.
+ * @return The property reference (never null).
+ * @throws MappingException If the property could not be found.
+ */
public Property getReferencedProperty(String propertyPath) throws MappingException {
- Iterator iter = getReferenceablePropertyIterator();
try {
- return getRecursiveProperty( propertyPath, iter );
+ return getRecursiveProperty( propertyPath, getReferenceablePropertyIterator() );
}
- catch (MappingException e) {
+ catch ( MappingException e ) {
throw new MappingException(
- "property-ref not found: " + propertyPath +
- "in entity: " + getEntityName(), e
- );
+ "property-ref [" + propertyPath + "] not found on entity [" +
getEntityName() + "]", e
+ );
}
}
public Property getRecursiveProperty(String propertyPath) throws MappingException {
- Iterator iter = getPropertyIterator(); // getReferenceablePropertyIterator();
- if ( getIdentifierMapper() != null ) {
- ArrayList iterators = new ArrayList(2);
- iterators.add(iter);
- iterators.add( getIdentifierMapper().getPropertyIterator() );
- iter = new JoinedIterator( iterators );
- }
try {
- return getRecursiveProperty( propertyPath, iter );
+ return getRecursiveProperty( propertyPath, getPropertyIterator() );
}
- catch (MappingException e) {
+ catch ( MappingException e ) {
throw new MappingException(
- "property not found: " + propertyPath +
- "in entity: " + getEntityName(), e
- );
+ "property [" + propertyPath + "] not found on entity [" +
getEntityName() + "]", e
+ );
}
}
private Property getRecursiveProperty(String propertyPath, Iterator iter) throws
MappingException {
Property property = null;
-
- StringTokenizer st = new StringTokenizer( propertyPath, ".", false);
+ StringTokenizer st = new StringTokenizer( propertyPath, ".", false );
try {
while ( st.hasMoreElements() ) {
- String element = (String) st.nextElement();
- if (property == null) {
+ final String element = ( String ) st.nextElement();
+ if ( property == null ) {
Property identifierProperty = getIdentifierProperty();
- if ( identifierProperty != null
- && identifierProperty.getName().equals( StringHelper.root(element) ) ) {
+ if ( identifierProperty != null && identifierProperty.getName().equals(
element ) ) {
+ // we have a mapped identifier property and the root of
+ // the incoming property path matched that identifier
+ // property
property = identifierProperty;
}
- else {
+ else if ( identifierProperty == null && getIdentifierMapper() != null ) {
+ // we have an embedded composite identifier
+ identifierProperty = getProperty( element,
getIdentifierMapper().getPropertyIterator() );
+ if ( identifierProperty != null ) {
+ // the root of the incoming property path matched one
+ // of the embedded composite identifier properties
+ property = identifierProperty;
+ }
+ }
+
+ if ( property == null ) {
property = getProperty( element, iter );
}
}
else {
//flat recursive algorithm
- property = ( (Component) property.getValue() ).getProperty(element);
+ property = ( ( Component ) property.getValue() ).getProperty( element );
}
}
}
- catch (MappingException e) {
- throw new MappingException(
- "property not found: " + propertyPath +
- "in entity: " + getEntityName(), e
- );
+ catch ( MappingException e ) {
+ throw new MappingException( "property [" + propertyPath + "] not found
on entity [" + getEntityName() + "]" );
}
return property;
@@ -387,7 +401,7 @@
return prop;
}
}
- throw new MappingException("property not found: " + propertyName + " on
entity " + getEntityName());
+ throw new MappingException( "property [" + propertyName + "] not found
on entity [" + getEntityName() + "]" );
}
public Property getProperty(String propertyName) throws MappingException {
@@ -497,16 +511,33 @@
return 0;
}
+ /**
+ * Build an iterator over the properties defined on this class. The returned
+ * iterator only accounts for "normal" properties (i.e. non-identifier
+ * properties).
+ * <p/>
+ * Differs from {@link #getUnjoinedPropertyIterator} in that the iterator
+ * we return here will include properties defined as part of a join.
+ *
+ * @return An iterator over the "normal" properties.
+ */
public Iterator getPropertyIterator() {
ArrayList iterators = new ArrayList();
iterators.add( properties.iterator() );
- for ( int i=0; i<joins.size(); i++ ) {
- Join join = (Join) joins.get(i);
+ for ( int i = 0; i < joins.size(); i++ ) {
+ Join join = ( Join ) joins.get( i );
iterators.add( join.getPropertyIterator() );
}
- return new JoinedIterator(iterators);
+ return new JoinedIterator( iterators );
}
+ /**
+ * Build an iterator over the properties defined on this class <b>which
+ * are not defined as part of a join</b>. As with {@link #getPropertyIterator},
+ * the returned iterator only accounts for non-identifier properties.
+ *
+ * @return An iterator over the non-joined "normal" properties.
+ */
public Iterator getUnjoinedPropertyIterator() {
return properties.iterator();
}
Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:35:29 UTC (rev
10919)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:37:32 UTC (rev
10920)
@@ -22,7 +22,6 @@
import org.hibernate.test.collection.CollectionSuite;
import org.hibernate.test.component.ComponentTest;
import org.hibernate.test.compositeelement.CompositeElementTest;
-import org.hibernate.test.comppropertyref.ComponentPropertyRefTest;
import org.hibernate.test.connections.ConnectionsSuite;
import org.hibernate.test.criteria.CriteriaQueryTest;
import org.hibernate.test.cuk.CompositePropertyRefTest;
@@ -104,7 +103,7 @@
import org.hibernate.test.orphan.OrphanIdRollbackTest;
import org.hibernate.test.orphan.OrphanTest;
import org.hibernate.test.pagination.PaginationTest;
-import org.hibernate.test.propertyref.PropertyRefTest;
+import org.hibernate.test.propertyref.PropertyRefSuite;
import org.hibernate.test.proxy.ProxyTest;
import org.hibernate.test.querycache.QueryCacheTest;
import org.hibernate.test.readonly.ReadOnlyTest;
@@ -214,8 +213,7 @@
suite.addTest( org.hibernate.test.onetoone.singletable.OneToOneTest.suite() );
suite.addTest( org.hibernate.test.onetoonelink.OneToOneTest.suite() );
suite.addTest( OptimisticLockTest.suite() );
- suite.addTest( PropertyRefTest.suite() );
- suite.addTest( ComponentPropertyRefTest.suite() );
+ suite.addTest( PropertyRefSuite.suite() );
suite.addTest( org.hibernate.test.joineduid.PropertyRefTest.suite() );
suite.addTest( org.hibernate.test.orphan.PropertyRefTest.suite() );
suite.addTest( SubclassPropertyRefTest.suite() );
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/Account.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/Account.java 2006-12-05 14:35:29
UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/Account.java 2006-12-05 14:37:32
UTC (rev 10920)
@@ -1,48 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-/**
- * @author Gavin King
- */
-public class Account {
- private String accountId;
- private Person user;
- private char type;
- /**
- * @return Returns the user.
- */
- public Person getUser() {
- return user;
- }
- /**
- * @param user The user to set.
- */
- public void setUser(Person user) {
- this.user = user;
- }
- /**
- * @return Returns the accountId.
- */
- public String getAccountId() {
- return accountId;
- }
- /**
- * @param accountId The accountId to set.
- */
- public void setAccountId(String accountId) {
- this.accountId = accountId;
- }
- /**
- * @return Returns the type.
- */
- public char getType() {
- return type;
- }
- /**
- * @param type The type to set.
- */
- public void setType(char type) {
- this.type = type;
- }
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/Address.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/Address.java 2006-12-05 14:35:29
UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/Address.java 2006-12-05 14:37:32
UTC (rev 10920)
@@ -1,73 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-/**
- * @author gavin
- */
-public class Address {
- private Long id;
- private String address;
- private String zip;
- private String country;
- private Person person;
- /**
- * @return Returns the id.
- */
- public Long getId() {
- return id;
- }
- /**
- * @param id The id to set.
- */
- public void setId(Long id) {
- this.id = id;
- }
- /**
- * @return Returns the person.
- */
- public Person getPerson() {
- return person;
- }
- /**
- * @param person The person to set.
- */
- public void setPerson(Person person) {
- this.person = person;
- }
- /**
- * @return Returns the address.
- */
- public String getAddress() {
- return address;
- }
- /**
- * @param address The address to set.
- */
- public void setAddress(String address) {
- this.address = address;
- }
- /**
- * @return Returns the country.
- */
- public String getCountry() {
- return country;
- }
- /**
- * @param country The country to set.
- */
- public void setCountry(String country) {
- this.country = country;
- }
- /**
- * @return Returns the zip.
- */
- public String getZip() {
- return zip;
- }
- /**
- * @param zip The zip to set.
- */
- public void setZip(String zip) {
- this.zip = zip;
- }
-}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,27 @@
+package org.hibernate.test.propertyref;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.propertyref.basic.PropertyRefTest;
+import
org.hibernate.test.propertyref.component.cid.embedded.PartialEmbeddedCidPropertyRefTest;
+import org.hibernate.test.propertyref.component.cid.mapped.PartialCidPropertyRefTest;
+import org.hibernate.test.propertyref.component.partial.ComponentPropertyRefTest;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PropertyRefSuite {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "property-ref suite" );
+ suite.addTest( PropertyRefTest.suite() );
+ suite.addTest( ComponentPropertyRefTest.suite() );
+ suite.addTest( PartialEmbeddedCidPropertyRefTest.suite() );
+ suite.addTest( PartialCidPropertyRefTest.suite() );
+ return suite;
+ }
+
+}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,48 @@
+//$Id: Account.java 4399 2004-08-21 08:43:20Z oneovthafew $
+package org.hibernate.test.propertyref.basic;
+
+/**
+ * @author Gavin King
+ */
+public class Account {
+ private String accountId;
+ private Person user;
+ private char type;
+ /**
+ * @return Returns the user.
+ */
+ public Person getUser() {
+ return user;
+ }
+ /**
+ * @param user The user to set.
+ */
+ public void setUser(Person user) {
+ this.user = user;
+ }
+ /**
+ * @return Returns the accountId.
+ */
+ public String getAccountId() {
+ return accountId;
+ }
+ /**
+ * @param accountId The accountId to set.
+ */
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public char getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(char type) {
+ this.type = type;
+ }
+
+}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,73 @@
+//$Id: Address.java 4390 2004-08-20 07:54:48Z oneovthafew $
+package org.hibernate.test.propertyref.basic;
+
+/**
+ * @author gavin
+ */
+public class Address {
+ private Long id;
+ private String address;
+ private String zip;
+ private String country;
+ private Person person;
+ /**
+ * @return Returns the id.
+ */
+ public Long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the person.
+ */
+ public Person getPerson() {
+ return person;
+ }
+ /**
+ * @param person The person to set.
+ */
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+ /**
+ * @return Returns the address.
+ */
+ public String getAddress() {
+ return address;
+ }
+ /**
+ * @param address The address to set.
+ */
+ public void setAddress(String address) {
+ this.address = address;
+ }
+ /**
+ * @return Returns the country.
+ */
+ public String getCountry() {
+ return country;
+ }
+ /**
+ * @param country The country to set.
+ */
+ public void setCountry(String country) {
+ this.country = country;
+ }
+ /**
+ * @return Returns the zip.
+ */
+ public String getZip() {
+ return zip;
+ }
+ /**
+ * @param zip The zip to set.
+ */
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,23 @@
+//$Id: Group.java 7589 2005-07-21 01:56:42Z oneovthafew $
+package org.hibernate.test.propertyref.basic;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Group {
+ private String name;
+ private Set users = new HashSet();
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Set getUsers() {
+ return users;
+ }
+ public void setUsers(Set users) {
+ this.users = users;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+ Demonstrates the use of property-ref to map legacy data where
+ foreign keys reference something other than the primary key of
+ the associated entity. Here we show:
+
+ (1) A one-to-one foreign key association (prefer primary key
+ associations)
+
+ (2) A bidirectional one-to-many association on a key that is
+ not the primary key (prefer associations from foreign keys
+ to primary keys)
+
+-->
+
+<hibernate-mapping package="org.hibernate.test.propertyref.basic">
+
+ <class name="Person">
+ <id name="id">
+ <generator class="hilo"/>
+ </id>
+
+ <property name="name" length="100"/>
+ <property name="userId" column="person_userid"
length="8" unique="true"/>
+
+ <one-to-one name="address" property-ref="person"
cascade="all" fetch="join"/>
+
+ <set name="accounts" inverse="true">
+ <key column="userId" property-ref="userId"/>
+ <one-to-many class="Account"/>
+ </set>
+
+ <bag name="systems" table="USER_SYSTEM"
lazy="false" inverse="false" cascade="all">
+ <key column="USER_ID" property-ref="userId" />
+ <element type="string" column="SYSTEM" />
+ </bag>
+ </class>
+
+ <class name="Address">
+ <id name="id">
+ <generator class="hilo"/>
+ </id>
+
+ <property name="address" length="300"/>
+ <property name="zip" length="5"/>
+ <property name="country" length="25"/>
+ <many-to-one name="person" unique="true"
not-null="true"/>
+ </class>
+
+ <class name="Account">
+ <id name="accountId" length="32">
+ <generator class="uuid.hex"/>
+ </id>
+
+ <many-to-one name="user"
+ column="userId"
+ property-ref="userId"/>
+
+ <property name="type" not-null="true"/>
+
+ </class>
+
+ <class name="Group" table="`Group`">
+ <id name="name"/>
+ <set name="users" table="UserGroup"
cascade="save-update">
+ <key column="groupName"/>
+ <many-to-many column="userId" class="Person"
property-ref="userId"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,88 @@
+//$Id: Person.java 10396 2006-09-01 08:48:02 -0500 (Fri, 01 Sep 2006)
steve.ebersole(a)jboss.com $
+package org.hibernate.test.propertyref.basic;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author gavin
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private Address address;
+ private String userId;
+ private Set accounts = new HashSet();
+ private List systems = new ArrayList();
+
+ /**
+ * @return Returns the userId.
+ */
+ public String getUserId() {
+ return userId;
+ }
+ /**
+ * @param userId The userId to set.
+ */
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+ /**
+ * @return Returns the address.
+ */
+ public Address getAddress() {
+ return address;
+ }
+ /**
+ * @param address The address to set.
+ */
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public Long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ /**
+ * @return Returns the accounts.
+ */
+ public Set getAccounts() {
+ return accounts;
+ }
+ /**
+ * @param accounts The accounts to set.
+ */
+ public void setAccounts(Set accounts) {
+ this.accounts = accounts;
+ }
+
+ public List getSystems() {
+ return systems;
+ }
+
+ public void setSystems(List systems) {
+ this.systems = systems;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,269 @@
+//$Id: PropertyRefTest.java 10396 2006-09-01 08:48:02 -0500 (Fri, 01 Sep 2006)
steve.ebersole(a)jboss.com $
+package org.hibernate.test.propertyref.basic;
+
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.FetchMode;
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.ForeignKey;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.test.TestCase;
+
+/**
+ * @author Gavin King
+ */
+public class PropertyRefTest extends TestCase {
+
+ public PropertyRefTest(String str) {
+ super(str);
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/basic/Person.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite(PropertyRefTest.class);
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "1");
+ cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ public void testNonLazyBagKeyPropertyRef() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName( "Steve" );
+ p.setUserId( "steve" );
+ p.getSystems().add( "QA" );
+ p.getSystems().add( "R&D" );
+ s.persist( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.createQuery( "from Person" ).list();
+ s.clear();
+ s.createSQLQuery( "select {p.*} from Person {p}" )
+ .addEntity( "p", Person.class.getName() )
+ .list();
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ List results = s.createQuery( "from Person" ).list();
+ Iterator itr = results.iterator();
+ while ( itr.hasNext() ) {
+ s.delete( itr.next() );
+ }
+ t.commit();
+ s.close();
+ }
+
+ public void testManyToManyPropertyRef() {
+ // prepare some test data relating to the Group->Person many-to-many association
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName( "Steve" );
+ p.setUserId( "steve" );
+ s.persist( p );
+ Group g = new Group();
+ g.setName( "Admins" );
+ g.getUsers().add( p );
+ s.persist( g );
+ // force a flush and detachment here to test reattachment handling of the property-ref
(HHH-1531)
+ t.commit();
+ s.close();
+
+ Person p2 = new Person();
+ p2.setName( "Max" );
+ p2.setUserId( "max" );
+ g.getUsers().add( p2 );
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.update( g );
+ t.commit();
+ s.close();
+
+ // test retrieval of the group
+ s = openSession();
+ t = s.beginTransaction();
+ g = ( Group ) s.createQuery( "from Group g left join fetch g.users"
).uniqueResult();
+ assertTrue( Hibernate.isInitialized( g.getUsers() ) );
+ assertEquals( 2, g.getUsers().size() );
+ s.delete( g );
+ s.createQuery( "delete Person" ).executeUpdate();
+ t.commit();
+ s.close();
+ }
+
+ public void testOneToOnePropertyRef() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName("Steve");
+ p.setUserId("steve");
+ Address a = new Address();
+ a.setAddress("Texas");
+ a.setCountry("USA");
+ p.setAddress(a);
+ a.setPerson(p);
+ s.save(p);
+ Person p2 = new Person();
+ p2.setName("Max");
+ p2.setUserId("max");
+ s.save(p2);
+ Account act = new Account();
+ act.setType('c');
+ act.setUser(p2);
+ p2.getAccounts().add(act);
+ s.save(act);
+ s.flush();
+ s.clear();
+
+ p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
+ p2 = (Person) s.get( Person.class, p2.getId() ); //get null address reference by outer
join
+ assertNull( p2.getAddress() );
+ assertNotNull( p.getAddress() );
+ List l = s.createQuery("from Person").list(); //pull address references for
cache
+ assertEquals( l.size(), 2 );
+ assertTrue( l.contains(p) && l.contains(p2) );
+ s.clear();
+
+ l = s.createQuery("from Person p order by p.name").list(); //get address
references by sequential selects
+ assertEquals( l.size(), 2 );
+ assertNull( ( (Person) l.get(0) ).getAddress() );
+ assertNotNull( ( (Person) l.get(1) ).getAddress() );
+ s.clear();
+
+ l = s.createQuery("from Person p left join fetch p.address a order by
a.country").list(); //get em by outer join
+ assertEquals( l.size(), 2 );
+ if ( ( (Person) l.get(0) ).getName().equals("Max") ) {
+ assertNull( ( (Person) l.get(0) ).getAddress() );
+ assertNotNull( ( (Person) l.get(1) ).getAddress() );
+ }
+ else {
+ assertNull( ( (Person) l.get(1) ).getAddress() );
+ assertNotNull( ( (Person) l.get(0) ).getAddress() );
+ }
+ s.clear();
+
+ l = s.createQuery("from Person p left join p.accounts a").list();
+ for ( int i=0; i<2; i++ ) {
+ Object[] row = (Object[]) l.get(i);
+ Person px = (Person) row[0];
+ assertFalse( Hibernate.isInitialized( px.getAccounts() ) );
+ assertTrue( px.getAccounts().size()>0 || row[1]==null );
+ }
+ s.clear();
+
+ l = s.createQuery("from Person p left join fetch p.accounts a order by
p.name").list();
+ Person p0 = (Person) l.get(0);
+ assertTrue( Hibernate.isInitialized( p0.getAccounts() ) );
+ assertEquals( p0.getAccounts().size(), 1 );
+ assertSame( ( (Account) p0.getAccounts().iterator().next() ).getUser(), p0 );
+ Person p1 = (Person) l.get(1);
+ assertTrue( Hibernate.isInitialized( p1.getAccounts() ) );
+ assertEquals( p1.getAccounts().size(), 0 );
+ s.clear();
+ Account acc = (Account) s.createQuery("from Account a left join fetch
a.user").uniqueResult();
+ assertTrue( Hibernate.isInitialized(acc.getUser()) );
+ assertNotNull(acc.getUser());
+ assertTrue( acc.getUser().getAccounts().contains(acc) );
+
+ s.createQuery("delete from Address").executeUpdate();
+ s.createQuery("delete from Account").executeUpdate(); // to not break
constraint violation between Person and Account
+ s.createQuery("delete from Person").executeUpdate();
+
+ t.commit();
+ s.close();
+ }
+
+
+ public void testJoinFetchPropertyRef() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName("Steve");
+ p.setUserId("steve");
+ Address a = new Address();
+ a.setAddress("Texas");
+ a.setCountry("USA");
+ p.setAddress(a);
+ a.setPerson(p);
+ s.save(p);
+
+ s.flush();
+ s.clear();
+
+ getSessions().getStatistics().clear();
+
+ p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
+
+ assertTrue( Hibernate.isInitialized( p.getAddress() ) );
+ assertNotNull( p.getAddress() );
+ assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 1 );
+ assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
+
+ s.clear();
+
+ getSessions().getStatistics().clear();
+
+ p = (Person) s.createCriteria(Person.class)
+ .setFetchMode("address", FetchMode.SELECT)
+ .uniqueResult(); //get address reference by select
+
+ assertTrue( Hibernate.isInitialized( p.getAddress() ) );
+ assertNotNull( p.getAddress() );
+ assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 2 );
+ assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
+
+ s.createQuery("delete from Address").executeUpdate();
+ s.createQuery("delete from Person").executeUpdate();
+
+ t.commit();
+ s.close();
+ }
+
+ public void testForeignKeyCreation() {
+ PersistentClass classMapping =
getCfg().getClassMapping("org.hibernate.test.propertyref.basic.Account");
+
+ Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
+ boolean found = false;
+ while ( foreignKeyIterator.hasNext() ) {
+ ForeignKey element = (ForeignKey) foreignKeyIterator.next();
+ if(element.getReferencedEntityName().equals(Person.class.getName() ) ) {
+
+ if(!element.isReferenceToPrimaryKey() ) {
+ List referencedColumns = element.getReferencedColumns();
+ Column column = (Column) referencedColumns.get(0);
+ if(column.getName().equals("person_userid") ) {
+ found = true; // extend test to include the columns
+ }
+ }
+ }
+ }
+
+ assertTrue("Property ref foreign key not found",found);
+ }
+}
+
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,23 @@
+package org.hibernate.test.propertyref.component.complete;
+
+
+public class Account {
+ private String number;
+ private Person owner;
+
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,71 @@
+package org.hibernate.test.propertyref.component.complete;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+
+/**
+ * @author Gavin King
+ */
+public class CompleteComponentPropertyRefTest extends TestCase {
+
+ public CompleteComponentPropertyRefTest(String str) {
+ super(str);
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/component/complete/Mapping.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( CompleteComponentPropertyRefTest.class);
+ }
+
+ public void testComponentPropertyRef() {
+ Person p = new Person();
+ p.setIdentity( new Identity() );
+ Account a = new Account();
+ a.setNumber("123-12345-1236");
+ a.setOwner(p);
+ p.getIdentity().setName("Gavin");
+ p.getIdentity().setSsn("123-12-1234");
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist(p);
+ s.persist(a);
+ s.flush();
+ s.clear();
+
+ a = (Account) s.createQuery("from Account a left join fetch
a.owner").uniqueResult();
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ s.clear();
+
+ a = (Account) s.get(Account.class, "123-12345-1236");
+ assertFalse( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+
+ s.clear();
+
+ getSessions().evict(Account.class);
+ getSessions().evict(Person.class);
+
+ a = (Account) s.get(Account.class, "123-12345-1236");
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+
+ s.delete( a );
+ s.delete( a.getOwner() );
+ tx.commit();
+ s.close();
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,21 @@
+package org.hibernate.test.propertyref.component.complete;
+
+import java.io.Serializable;
+
+public class Identity implements Serializable {
+ private String name;
+ private String ssn;
+
+ public String getSsn() {
+ return ssn;
+ }
+ public void setSsn(String id) {
+ this.ssn = id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+
+-->
+
+<hibernate-mapping
package="org.hibernate.test.propertyref.component.complete">
+
+ <class name="Person" table="COMP_COMP_PROPREF_PERSON">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <component name="identity" class="Identity">
+ <property name="name"/>
+ <property name="ssn" unique="true"/>
+ </component>
+ </class>
+
+ <class name="Account" table="COMP_COMP_PROPREF_ACCT">
+ <id name="number" column="accnum"/>
+ <many-to-one name="owner" property-ref="identity">
+ <column name="OWNER_NAME" />
+ <column name="OWNER_SSN" />
+ </many-to-one>
+ </class>
+
+</hibernate-mapping>
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,20 @@
+package org.hibernate.test.propertyref.component.complete;
+
+
+public class Person {
+ private Long id;
+ private Identity identity;
+
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public Identity getIdentity() {
+ return identity;
+ }
+ public void setIdentity(Identity identity) {
+ this.identity = identity;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,23 @@
+//$Id: Account.java 7587 2005-07-21 01:22:38Z oneovthafew $
+package org.hibernate.test.propertyref.component.partial;
+
+public class Account {
+ private String number;
+ private Person owner;
+
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,20 @@
+//$Id: Identity.java 7587 2005-07-21 01:22:38Z oneovthafew $
+package org.hibernate.test.propertyref.component.partial;
+
+public class Identity {
+ private String name;
+ private String ssn;
+
+ public String getSsn() {
+ return ssn;
+ }
+ public void setSsn(String id) {
+ this.ssn = id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+
+-->
+
+<hibernate-mapping
package="org.hibernate.test.propertyref.component.partial">
+
+ <class name="Person" table="PART_COMP_PROPREF_PERS">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <component name="identity">
+ <property name="name"/>
+ <property name="ssn" unique="true"/>
+ </component>
+ </class>
+
+ <class name="Account" table="PART_COMP_PROPREF_ACCT">
+ <id name="number" column="accnum"/>
+ <many-to-one name="owner" property-ref="identity.ssn"/>
+ </class>
+
+</hibernate-mapping>
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,73 @@
+//$Id: PartialComponentPropertyRefTest.java 9914 2006-05-09 09:37:18Z
max.andersen(a)jboss.com $
+package org.hibernate.test.propertyref.component.partial;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.TestCase;
+
+/**
+ * @author Gavin King
+ */
+public class PartialComponentPropertyRefTest extends TestCase {
+
+ public PartialComponentPropertyRefTest(String str) {
+ super(str);
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/component/partial/Mapping.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PartialComponentPropertyRefTest.class);
+ }
+
+ public void testComponentPropertyRef() {
+ Person p = new Person();
+ p.setIdentity( new Identity() );
+ Account a = new Account();
+ a.setNumber("123-12345-1236");
+ a.setOwner(p);
+ p.getIdentity().setName("Gavin");
+ p.getIdentity().setSsn("123-12-1234");
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist(p);
+ s.persist(a);
+ s.flush();
+ s.clear();
+
+ a = (Account) s.createQuery("from Account a left join fetch
a.owner").uniqueResult();
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ s.clear();
+
+ a = (Account) s.get(Account.class, "123-12345-1236");
+ assertFalse( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+
+ s.clear();
+
+ getSessions().evict(Account.class);
+ getSessions().evict(Person.class);
+
+ a = (Account) s.get(Account.class, "123-12345-1236");
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+ assertNotNull( a.getOwner() );
+ assertEquals( "Gavin", a.getOwner().getIdentity().getName() );
+ assertTrue( Hibernate.isInitialized( a.getOwner() ) );
+
+ s.delete( a );
+ s.delete( a.getOwner() );
+ tx.commit();
+ s.close();
+ }
+}
+
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,20 @@
+//$Id: Person.java 7587 2005-07-21 01:22:38Z oneovthafew $
+package org.hibernate.test.propertyref.component.partial;
+
+public class Person {
+ private Long id;
+ private Identity identity;
+
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public Identity getIdentity() {
+ return identity;
+ }
+ public void setIdentity(Identity identity) {
+ this.identity = identity;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,57 @@
+//$Id: Account.java 6029 2005-03-06 16:34:16Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.discrim;
+
+/**
+ * @author Gavin King
+ */
+public class Account {
+ private String accountId;
+ private Customer customer;
+ private Person person;
+ private char type;
+ /**
+ * @return Returns the user.
+ */
+ public Customer getCustomer() {
+ return customer;
+ }
+ /**
+ * @param user The user to set.
+ */
+ public void setCustomer(Customer user) {
+ this.customer = user;
+ }
+ /**
+ * @return Returns the accountId.
+ */
+ public String getAccountId() {
+ return accountId;
+ }
+ /**
+ * @param accountId The accountId to set.
+ */
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public char getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(char type) {
+ this.type = type;
+ }
+ public Person getPerson() {
+ return person;
+ }
+
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,18 @@
+//$Id: Customer.java 6029 2005-03-06 16:34:16Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.discrim;
+
+/**
+ * @author Gavin King
+ */
+public class Customer extends Person {
+ private String customerId;
+
+ public String getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(String customerId) {
+ this.customerId = customerId;
+ }
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping
package="org.hibernate.test.propertyref.inheritence.discrim">
+
+ <class name="Person" discriminator-value="null"
table="D_SBCLS_PROPREF_PERS">
+ <id name="id">
+ <generator class="hilo"/>
+ </id>
+ <discriminator formula="customerId"/>
+ <property name="name" length="100"/>
+ <property name="personId" length="8"
unique="true"/>
+
+ <subclass name="Customer" discriminator-value="not null">
+ <property name="customerId" length="8"
unique="true"/>
+ </subclass>
+ </class>
+
+ <class name="Account" table="D_SBCLS_PROPREF_ACCT">
+ <id name="accountId" length="32">
+ <generator class="uuid.hex"/>
+ </id>
+ <many-to-one name="person" column="personId"
unique="true" property-ref="personId"/>
+ <many-to-one name="customer" column="customerPersonId"
unique="true" property-ref="personId"/>
+ <property name="type" not-null="true"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,44 @@
+//$Id: Person.java 6029 2005-03-06 16:34:16Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.discrim;
+
+
+/**
+ * @author gavin
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private String personId;
+ /**
+ * @return Returns the id.
+ */
+ public Long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPersonId() {
+ return personId;
+ }
+
+ public void setPersonId(String personId) {
+ this.personId = personId;
+ }
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,64 @@
+//$Id: SubclassPropertyRefTest.java 6029 2005-03-06 16:34:16Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.discrim;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.TestCase;
+
+/**
+ * @author Gavin King
+ */
+public class SubclassPropertyRefTest extends TestCase {
+
+ public SubclassPropertyRefTest(String str) {
+ super( str );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/inheritence/discrim/Person.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( SubclassPropertyRefTest.class );
+ }
+
+ public void testOneToOnePropertyRef() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Customer c = new Customer();
+ c.setName( "Emmanuel" );
+ c.setCustomerId( "C123-456" );
+ c.setPersonId( "P123-456" );
+ Account a = new Account();
+ a.setCustomer( c );
+ a.setPerson( c );
+ a.setType( 'X' );
+ s.persist( c );
+ s.persist( a );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join
fetch acc.person" )
+ .uniqueResult();
+ assertNotNull( a.getCustomer() );
+ assertTrue( Hibernate.isInitialized( a.getCustomer() ) );
+ assertNotNull( a.getPerson() );
+ assertTrue( Hibernate.isInitialized( a.getPerson() ) );
+ c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();
+ assertSame( c, a.getCustomer() );
+ assertSame( c, a.getPerson() );
+ s.delete( a );
+ s.delete( a.getCustomer() );
+ s.delete( a.getPerson() );
+ t.commit();
+ s.close();
+ }
+
+}
+
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,38 @@
+//$Id: Account.java 7274 2005-06-22 17:07:29Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.joined;
+
+import java.io.Serializable;
+
+/**
+ * @author Gavin King
+ */
+public class Account implements Serializable {
+ private String accountId;
+ private char type;
+
+ /**
+ * @return Returns the accountId.
+ */
+ public String getAccountId() {
+ return accountId;
+ }
+ /**
+ * @param accountId The accountId to set.
+ */
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public char getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(char type) {
+ this.type = type;
+ }
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,23 @@
+//$Id: BankAccount.java 7274 2005-06-22 17:07:29Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.joined;
+
+public class BankAccount extends Account {
+ private String accountNumber;
+ private String bsb;
+
+ public String getAccountNumber() {
+ return accountNumber;
+ }
+
+ public void setAccountNumber(String accountNumber) {
+ this.accountNumber = accountNumber;
+ }
+
+ public String getBsb() {
+ return bsb;
+ }
+
+ public void setBsb(String bsb) {
+ this.bsb = bsb;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,70 @@
+//$Id: PropertyRefTest.java 7275 2005-06-22 18:58:16Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.joined;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.FetchMode;
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.TestCase;
+
+/**
+ * @author Gavin King
+ */
+public class JoinedSubclassPropertyRefTest extends TestCase {
+
+ public JoinedSubclassPropertyRefTest(String str) {
+ super(str);
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/inheritence/joined/Person.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( JoinedSubclassPropertyRefTest.class);
+ }
+
+ public void testPropertyRefToJoinedSubclass() {
+ 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();
+ }
+
+}
+
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+ Demonstrates the use of property-ref to map legacy data where
+ foreign keys reference something other than the primary key of
+ the associated entity. Here we show:
+
+ (1) A one-to-one foreign key association (prefer primary key
+ associations)
+
+ (2) A bidirectional one-to-many association on a key that is
+ not the primary key (prefer associations from foreign keys
+ to primary keys)
+
+-->
+
+<hibernate-mapping
package="org.hibernate.test.propertyref.inheritence.joined">
+
+ <class name="Person" table="J_SBCLS_PROPREF_PERS">
+ <id name="id">
+ <generator class="hilo"/>
+ </id>
+ <property name="name" length="100"/>
+ <many-to-one name="bankAccount" property-ref="bsbAccountNumber"
cascade="all">
+ <column name="bsb"/>
+ <column name="accountNumber"/>
+ </many-to-one>
+ </class>
+
+ <class name="Account" table="J_SBCLS_PROPREF_ACCT">
+ <id name="accountId" length="32">
+ <generator class="uuid"/>
+ </id>
+ <property name="type" not-null="true"/>
+ <joined-subclass name="BankAccount"
table="J_SBCLS_PROPREF_BACCT">
+ <key column="accountId"/>
+ <properties unique="true" name="bsbAccountNumber">
+ <property name="bsb" length="4"
not-null="true"/>
+ <property name="accountNumber" length="16"
not-null="true"/>
+ </properties>
+ </joined-subclass>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,44 @@
+//$Id: Person.java 7274 2005-06-22 17:07:29Z oneovthafew $
+package org.hibernate.test.propertyref.inheritence.joined;
+
+
+/**
+ * @author gavin
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private BankAccount bankAccount;
+
+ /**
+ * @return Returns the id.
+ */
+ public Long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public BankAccount getBankAccount() {
+ return bankAccount;
+ }
+ public void setBankAccount(BankAccount bankAccount) {
+ this.bankAccount = bankAccount;
+ }
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,56 @@
+package org.hibernate.test.propertyref.inheritence.union;
+
+/**
+ * @author Gavin King
+ */
+public class Account {
+ private String accountId;
+ private Customer customer;
+ private Person person;
+ private char type;
+ /**
+ * @return Returns the user.
+ */
+ public Customer getCustomer() {
+ return customer;
+ }
+ /**
+ * @param user The user to set.
+ */
+ public void setCustomer(Customer user) {
+ this.customer = user;
+ }
+ /**
+ * @return Returns the accountId.
+ */
+ public String getAccountId() {
+ return accountId;
+ }
+ /**
+ * @param accountId The accountId to set.
+ */
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public char getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(char type) {
+ this.type = type;
+ }
+ public Person getPerson() {
+ return person;
+ }
+
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,17 @@
+package org.hibernate.test.propertyref.inheritence.union;
+
+/**
+ * @author Gavin King
+ */
+public class Customer extends Person {
+ private String customerId;
+
+ public String getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(String customerId) {
+ this.customerId = customerId;
+ }
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping
package="org.hibernate.test.propertyref.inheritence.union">
+
+ <class name="Person" table="U_SBCLS_PROPREF_PERS">
+ <id name="id">
+ <generator class="hilo"/>
+ </id>
+ <property name="name" length="100"/>
+ <property name="personId" length="8"
unique="true"/>
+
+ <union-subclass name="Customer"
table="U_SBCLS_PROPREF_CUST">
+ <property name="customerId" length="8"
unique="true"/>
+ </union-subclass>
+ </class>
+
+ <class name="Account" table="U_SBCLS_PROPREF_ACCT">
+ <id name="accountId" length="32">
+ <generator class="uuid.hex"/>
+ </id>
+ <many-to-one name="person" column="personId"
unique="true" property-ref="personId"/>
+ <many-to-one name="customer" column="customerPersonId"
unique="true" property-ref="personId"/>
+ <property name="type" not-null="true"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,42 @@
+package org.hibernate.test.propertyref.inheritence.union;
+
+/**
+ * @author gavin
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private String personId;
+ /**
+ * @return Returns the id.
+ */
+ public Long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPersonId() {
+ return personId;
+ }
+
+ public void setPersonId(String personId) {
+ this.personId = personId;
+ }
+
+}
Added:
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java 2006-12-05
14:35:29 UTC (rev 10919)
+++
trunk/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java 2006-12-05
14:37:32 UTC (rev 10920)
@@ -0,0 +1,62 @@
+package org.hibernate.test.propertyref.inheritence.union;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+
+/**
+ * @author Gavin King
+ */
+public class UnionSubclassPropertyRefTest extends TestCase {
+
+ public UnionSubclassPropertyRefTest(String str) {
+ super( str );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "propertyref/inheritence/union/Person.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( UnionSubclassPropertyRefTest.class );
+ }
+
+ public void testOneToOnePropertyRef() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Customer c = new Customer();
+ c.setName( "Emmanuel" );
+ c.setCustomerId( "C123-456" );
+ c.setPersonId( "P123-456" );
+ Account a = new Account();
+ a.setCustomer( c );
+ a.setPerson( c );
+ a.setType( 'X' );
+ s.persist( c );
+ s.persist( a );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ a = ( Account ) s.createQuery( "from Account acc join fetch acc.customer join
fetch acc.person" )
+ .uniqueResult();
+ assertNotNull( a.getCustomer() );
+ assertTrue( Hibernate.isInitialized( a.getCustomer() ) );
+ assertNotNull( a.getPerson() );
+ assertTrue( Hibernate.isInitialized( a.getPerson() ) );
+ c = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();
+ assertSame( c, a.getCustomer() );
+ assertSame( c, a.getPerson() );
+ s.delete( a );
+ s.delete( a.getCustomer() );
+ s.delete( a.getPerson() );
+ t.commit();
+ s.close();
+ }
+
+}