Hibernate SVN: r10929 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/hql/ast/tree test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 14:04:53 -0500 (Tue, 05 Dec 2006)
New Revision: 10929
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
Log:
HHH-2257 : implicit joins and shallow queries
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/…
[View More]DotNode.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:00:32 UTC (rev 10928)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:04:53 UTC (rev 10929)
@@ -5,6 +5,7 @@
import org.hibernate.engine.JoinSequence;
import org.hibernate.hql.CollectionProperties;
import org.hibernate.hql.antlr.SqlTokenTypes;
+import org.hibernate.hql.antlr.HqlSqlTokenTypes;
import org.hibernate.hql.ast.util.ASTPrinter;
import org.hibernate.hql.ast.util.ASTUtil;
import org.hibernate.hql.ast.util.ColumnHelper;
@@ -286,26 +287,34 @@
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
checkForCorrelatedSubquery( "dereferenceEntity" );
- // Only join to the entity table if:
- // 1) we were instructed to generate any needed joins (generateJoins==true)
- // AND
- // 2) EITHER:
- // A) our parent represents a further dereference of this entity to anything
- // other than the entity's id property
- // OR
- // B) this node is in any clause, other than the select clause (unless that
- // select clause is part of a scalar query :/ )
+ // two general cases we check here:
+ // 1) is our parent a DotNode as well? If so, our property reference is
+ // being further de-referenced...
+ // 2) we were asked to generate any needed joins (generateJoins==true) *OR*
+ // the current parser state indicates to use an INNER JOIN for implicit joins
+ //
+ // The "implicit join" portion of the second condition was done to account for
+ // situations like HHH-2257 to make sure that iterate() and list() return
+ // consistent results. Previously the join would be skipped on "shallow queries"
+ // (aka, iterate()) for performance reasons, but that can lead to incorrect
+ // results since INNER JOINs do place extra restrications on the returned
+ // results.
DotNode parentAsDotNode = null;
String property = propertyName;
final boolean joinIsNeeded;
if ( isDotNode( parent ) ) {
+ // our parent is another dot node, meaning we are being further dereferenced.
+ // thus we need to generate a join unless the parent refers to the associated
+ // entity's PK (because 'our' table would know the FK).
parentAsDotNode = ( DotNode ) parent;
property = parentAsDotNode.propertyName;
joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
}
else {
- joinIsNeeded = generateJoin && ( !getWalker().isInSelect() || !getWalker().isShallowQuery() );
+ // otherwise we need to generate the join if we were asked to, or
+ // if the current implicit join type is INNER JOINs
+ joinIsNeeded = generateJoin || getWalker().getImpliedJoinType() == JoinFragment.INNER_JOIN;
}
if ( joinIsNeeded ) {
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-12-05 19:00:32 UTC (rev 10928)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-12-05 19:04:53 UTC (rev 10929)
@@ -76,6 +76,7 @@
return new String[] {
"hql/Animal.hbm.xml",
"hql/FooBarCopy.hbm.xml",
+ "hql/SimpleEntityWithAssociation.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
@@ -93,6 +94,94 @@
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
+ public void testImplicitJoinsInDifferentClauses() {
+ // HHH-2257 :
+ // both the classic and ast translators output the same syntactically valid sql
+ // for all of these cases; the issue is that shallow (iterate) and
+ // non-shallow (list/scroll) queries return different results because the
+ // shallow skips the inner join which "weeds out" results from the non-shallow queries.
+ // The results were initially different depending upon the clause(s) in which the
+ // implicit join occurred
+ Session s = openSession();
+ s.beginTransaction();
+ SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
+ SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
+ SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" );
+ s.save( e1 );
+ s.save( e2 );
+ s.save( owner );
+ s.getTransaction().commit();
+ s.close();
+
+ checkCounts( "select e.owner from SimpleAssociatedEntity e", 1, "implicit-join in select clause" );
+ checkCounts( "select e.id, e.owner from SimpleAssociatedEntity e", 1, "implicit-join in select clause" );
+ checkCounts( "from SimpleAssociatedEntity e order by e.owner", 1, "implicit-join in order-by clause" );
+ checkCounts( "select e.owner.id, count(*) from SimpleAssociatedEntity e group by e.owner", 1, "implicit-join in select and group-by clauses" );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e1 );
+ s.delete( e2 );
+ s.delete( owner );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private void checkCounts(String hql, int expected, String testCondition) {
+ Session s = openSession();
+ s.beginTransaction();
+ int count = determineCount( s.createQuery( hql ).list().iterator() );
+ assertEquals( "list() [" + testCondition + "]", expected, count );
+ count = determineCount( s.createQuery( hql ).iterate() );
+ assertEquals( "iterate() [" + testCondition + "]", expected, count );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testImplicitSelectEntityAssociationInShallowQuery() {
+ // HHH-2257 :
+ // both the classic and ast translators output the same syntactically valid sql.
+ // the issue is that shallow and non-shallow queries return different
+ // results because the shallow skips the inner join which "weeds out" results
+ // from the non-shallow queries...
+ Session s = openSession();
+ s.beginTransaction();
+ SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
+ SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
+ SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" );
+ s.save( e1 );
+ s.save( e2 );
+ s.save( owner );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() );
+ assertEquals( 1, count ); // thing two would be removed from the result due to the inner join
+ count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() );
+ assertEquals( 1, count );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e1 );
+ s.delete( e2 );
+ s.delete( owner );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private int determineCount(Iterator iterator) {
+ int count = 0;
+ while( iterator.hasNext() ) {
+ count++;
+ iterator.next();
+ }
+ return count;
+ }
+
public void testNestedComponentIsNull() {
// (1) From MapTest originally...
// (2) Was then moved into HQLTest...
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:00:32 UTC (rev 10928)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:04:53 UTC (rev 10929)
@@ -498,6 +498,8 @@
return new String[] {
"hql/Animal.hbm.xml",
"hql/EntityWithCrazyCompositeKey.hbm.xml",
+ "hql/CrazyIdFieldNames.hbm.xml",
+ "hql/SimpleEntityWithAssociation.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
@@ -528,7 +530,6 @@
"legacy/UpDown.hbm.xml",
"compositeelement/Parent.hbm.xml",
"onetoone/joined/Person.hbm.xml",
- "hql/CrazyIdFieldNames.hbm.xml",
"any/Properties.hbm.xml"
};
}
[View Less]
18 years, 3 months
Hibernate SVN: r10928 - trunk/Hibernate3/test/org/hibernate/test/propertyref
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 14:00:32 -0500 (Tue, 05 Dec 2006)
New Revision: 10928
Modified:
trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
Log:
oops!
Modified: trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05 18:48:50 UTC (rev 10927)
+++ trunk/Hibernate3/…
[View More]test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05 19:00:32 UTC (rev 10928)
@@ -4,9 +4,11 @@
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;
+import org.hibernate.test.propertyref.component.complete.CompleteComponentPropertyRefTest;
+import org.hibernate.test.propertyref.component.partial.PartialComponentPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.discrim.SubclassPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.joined.JoinedSubclassPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.union.UnionSubclassPropertyRefTest;
/**
* {@inheritDoc}
@@ -14,14 +16,14 @@
* @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() );
+ suite.addTest( CompleteComponentPropertyRefTest.suite() );
+ suite.addTest( PartialComponentPropertyRefTest.suite() );
+ suite.addTest( SubclassPropertyRefTest.suite() );
+ suite.addTest( JoinedSubclassPropertyRefTest.suite() );
+ suite.addTest( UnionSubclassPropertyRefTest.suite() );
return suite;
}
-
}
[View Less]
18 years, 3 months
Hibernate SVN: r10927 - trunk/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 13:48:50 -0500 (Tue, 05 Dec 2006)
New Revision: 10927
Modified:
trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
Log:
HHH-2282 : PersistentClass propetty lookups and embedded composite identifiers;
consolidate property-ref tests
Modified: trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/…
[View More]PersistentClass.java 2006-12-05 18:48:42 UTC (rev 10926)
+++ trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 18:48:50 UTC (rev 10927)
@@ -369,12 +369,17 @@
}
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;
+ try {
+ 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;
+ }
}
+ catch( MappingException ignore ) {
+ // ignore it...
+ }
}
if ( property == null ) {
[View Less]
18 years, 3 months
Hibernate SVN: r10926 - branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 13:48:42 -0500 (Tue, 05 Dec 2006)
New Revision: 10926
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
Log:
HHH-2282 : PersistentClass propetty lookups and embedded composite identifiers;
consolidate property-ref tests
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- branches/Branch_3_2/…
[View More]Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 18:47:50 UTC (rev 10925)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 18:48:42 UTC (rev 10926)
@@ -374,12 +374,17 @@
}
else if ( identifierProperty == null && getIdentifier() != null && Component.class.isInstance( getIdentifier() ) ) {
// we have an embedded composite identifier
- identifierProperty = getProperty( element, ( ( Component ) getIdentifier() ).getPropertyIterator() );
- if ( identifierProperty != null ) {
- // the root of the incoming property path matched one
- // of the embedded composite identifier properties
- property = identifierProperty;
+ try {
+ identifierProperty = getProperty( element, ( ( Component ) getIdentifier() ).getPropertyIterator() );
+ if ( identifierProperty != null ) {
+ // the root of the incoming property path matched one
+ // of the embedded composite identifier properties
+ property = identifierProperty;
+ }
}
+ catch( MappingException ignore ) {
+ // ignore it...
+ }
}
if ( property == null ) {
[View Less]
18 years, 3 months
Hibernate SVN: r10925 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 13:47:50 -0500 (Tue, 05 Dec 2006)
New Revision: 10925
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
Log:
additional test query
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-12-…
[View More]05 18:47:29 UTC (rev 10924)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-12-05 18:47:50 UTC (rev 10925)
@@ -34,6 +34,7 @@
// caused problems with the "discriminator resolution" code; unable to reproduce)...
s.createQuery( "from MyEntity e where e.class = MySubclassEntity" );
s.createQuery( "from MyEntity e where e.other.class = MySubclassEntity" );
+ s.createQuery( "from MyEntity where other.class = MySubclassEntity" );
s.createQuery( "select object(I) from Item i").list();
s.close();
[View Less]
18 years, 3 months
Hibernate SVN: r10924 - trunk/Hibernate3/test/org/hibernate/test/jpa/ql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 13:47:29 -0500 (Tue, 05 Dec 2006)
New Revision: 10924
Modified:
trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
Log:
additional test query
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-12-05 14:55:02 UTC (rev 10923)
+++ trunk/…
[View More]Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-12-05 18:47:29 UTC (rev 10924)
@@ -35,6 +35,7 @@
// caused problems with the "discriminator resolution" code; unable to reproduce)...
s.createQuery( "from MyEntity e where e.class = MySubclassEntity" );
s.createQuery( "from MyEntity e where e.other.class = MySubclassEntity" );
+ s.createQuery( "from MyEntity where other.class = MySubclassEntity" );
s.createQuery( "select object(I) from Item i").list();
s.close();
[View Less]
18 years, 3 months
Hibernate SVN: r10923 - trunk/Hibernate3/test/org/hibernate/test/propertyref
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 09:55:02 -0500 (Tue, 05 Dec 2006)
New Revision: 10923
Removed:
trunk/Hibernate3/test/org/hibernate/test/propertyref/Group.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.java
trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java
Log:
HHH-2282 : PersistentClass propetty lookups and embedded composite identifiers;
consolidate …
[View More]property-ref tests
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/Group.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/Group.java 2006-12-05 14:40:29 UTC (rev 10922)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/Group.java 2006-12-05 14:55:02 UTC (rev 10923)
@@ -1,23 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-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;
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml 2006-12-05 14:40:29 UTC (rev 10922)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml 2006-12-05 14:55:02 UTC (rev 10923)
@@ -1,76 +0,0 @@
-<?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">
-
- <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
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.java 2006-12-05 14:40:29 UTC (rev 10922)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/Person.java 2006-12-05 14:55:02 UTC (rev 10923)
@@ -1,88 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-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;
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java 2006-12-05 14:40:29 UTC (rev 10922)
+++ trunk/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java 2006-12-05 14:55:02 UTC (rev 10923)
@@ -1,269 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-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);
- }
-
- 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.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);
- }
-
- protected String[] getMappings() {
- return new String[] { "propertyref/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;
- }
-}
-
[View Less]
18 years, 3 months
Hibernate SVN: r10922 - trunk/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 09:40:29 -0500 (Tue, 05 Dec 2006)
New Revision: 10922
Modified:
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/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:…
[View More]39:12 UTC (rev 10921)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:40:29 UTC (rev 10922)
@@ -115,7 +115,6 @@
import org.hibernate.test.subclassfilter.DiscrimSubclassFilterTest;
import org.hibernate.test.subclassfilter.JoinedSubclassFilterTest;
import org.hibernate.test.subclassfilter.UnionSubclassFilterTest;
-import org.hibernate.test.subclasspropertyref.SubclassPropertyRefTest;
import org.hibernate.test.subselect.SubselectTest;
import org.hibernate.test.subselectfetch.SubselectFetchTest;
import org.hibernate.test.ternary.TernaryTest;
@@ -214,9 +213,7 @@
suite.addTest( org.hibernate.test.onetoonelink.OneToOneTest.suite() );
suite.addTest( OptimisticLockTest.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() );
suite.addTest( NativeSqlSupportSuite.suite() );
suite.addTest( CriteriaQueryTest.suite() );
suite.addTest( SubselectTest.suite() );
[View Less]
18 years, 3 months
Hibernate SVN: r10921 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/cfg src/org/hibernate/mapping test/org/hibernate/test test/org/hibernate/test/propertyref test/org/hibernate/test/propertyref/basic test/org/hibernate/test/propertyref/component test/org/hibernate/test/propertyref/component/complete test/org/hibernate/test/propertyref/component/partial test/org/hibernate/test/propertyref/inheritence test/org/hibernate/test/propertyref/inheritence/discrim test/org/hibernate/test/
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 09:39:12 -0500 (Tue, 05 Dec 2006)
New Revision: 10921
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java
branches/Branch_3_2/Hibernate3/test/…
[View More]org/hibernate/test/propertyref/basic/Group.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2282 : PersistentClass propetty lookups and embedded composite identifiers;
consolidate property-ref tests
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -2397,7 +2397,7 @@
keyVal = collection.getOwner().getIdentifier();
}
else {
- keyVal = (KeyValue) collection.getOwner().getProperty( propRef ).getValue();
+ keyVal = (KeyValue) collection.getOwner().getReferencedProperty( propRef ).getValue();
}
SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal );
key.setCascadeDeleteEnabled( "cascade"
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -33,7 +33,7 @@
private String className;
private String proxyInterfaceName;
-
+
private String nodeName;
private String discriminatorValue;
@@ -115,7 +115,7 @@
abstract int nextSubclassId();
public abstract int getSubclassId();
-
+
public boolean useDynamicUpdate() {
return dynamicUpdate;
}
@@ -187,11 +187,11 @@
}
return new JoinedIterator(iters);
}
-
+
public Table getIdentityTable() {
return getRootTable();
}
-
+
public Iterator getDirectSubclasses() {
return subclasses.iterator();
}
@@ -310,71 +310,90 @@
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 ) {
+ // we are processing the root of the prpertyPath, so we have the following
+ // considerations:
+ // 1) specifically account for identifier properties
+ // 2) specifically account for embedded composite-identifiers
+ // 3) perform a normal property lookup
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 && getIdentifier() != null && Component.class.isInstance( getIdentifier() ) ) {
+ // we have an embedded composite identifier
+ identifierProperty = getProperty( element, ( ( Component ) getIdentifier() ).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 +406,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 {
@@ -425,7 +444,7 @@
checkPropertyDuplication();
checkColumnDuplication();
}
-
+
private void checkPropertyDuplication() throws MappingException {
HashSet names = new HashSet();
Iterator iter = getPropertyIterator();
@@ -459,7 +478,7 @@
public String toString() {
return getClass().getName() + '(' + getEntityName() + ')';
}
-
+
public Iterator getJoinIterator() {
return joins.iterator();
}
@@ -497,16 +516,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();
}
@@ -588,7 +624,7 @@
}
public abstract java.util.Set getSynchronizedTables();
-
+
public void addSynchronizedTable(String table) {
synchronizedTables.add(table);
}
@@ -601,26 +637,26 @@
this.isAbstract = isAbstract;
}
- protected void checkColumnDuplication(Set distinctColumns, Iterator columns)
+ protected void checkColumnDuplication(Set distinctColumns, Iterator columns)
throws MappingException {
while ( columns.hasNext() ) {
Selectable columnOrFormula = (Selectable) columns.next();
if ( !columnOrFormula.isFormula() ) {
Column col = (Column) columnOrFormula;
if ( !distinctColumns.add( col.getName() ) ) {
- throw new MappingException(
+ throw new MappingException(
"Repeated column in mapping for entity: " +
getEntityName() +
" column: " +
- col.getName() +
+ col.getName() +
" (should be mapped with insert=\"false\" update=\"false\")"
);
}
}
}
}
-
- protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties)
+
+ protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties)
throws MappingException {
while ( properties.hasNext() ) {
Property prop = (Property) properties.next();
@@ -635,15 +671,15 @@
}
}
}
-
+
protected Iterator getNonDuplicatedPropertyIterator() {
return getUnjoinedPropertyIterator();
}
-
+
protected Iterator getDiscriminatorColumnIterator() {
return EmptyIterator.INSTANCE;
}
-
+
protected void checkColumnDuplication() {
HashSet cols = new HashSet();
if (getIdentifierMapper() == null ) {
@@ -661,17 +697,17 @@
checkPropertyColumnDuplication( cols, join.getPropertyIterator() );
}
}
-
+
public abstract Object accept(PersistentClassVisitor mv);
-
+
public String getNodeName() {
return nodeName;
}
-
+
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
-
+
public boolean hasPojoRepresentation() {
return getClassName()!=null;
}
@@ -683,7 +719,7 @@
public boolean hasSubselectLoadableCollections() {
return hasSubselectLoadableCollections;
}
-
+
public void setSubselectLoadableCollections(boolean hasSubselectCollections) {
this.hasSubselectLoadableCollections = hasSubselectCollections;
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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;
@@ -116,7 +115,6 @@
import org.hibernate.test.subclassfilter.DiscrimSubclassFilterTest;
import org.hibernate.test.subclassfilter.JoinedSubclassFilterTest;
import org.hibernate.test.subclassfilter.UnionSubclassFilterTest;
-import org.hibernate.test.subclasspropertyref.SubclassPropertyRefTest;
import org.hibernate.test.subselect.SubselectTest;
import org.hibernate.test.subselectfetch.SubselectFetchTest;
import org.hibernate.test.ternary.TernaryTest;
@@ -214,11 +212,8 @@
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( org.hibernate.test.joineduid.PropertyRefTest.suite() );
+ suite.addTest( PropertyRefSuite.suite() );
suite.addTest( org.hibernate.test.orphan.PropertyRefTest.suite() );
- suite.addTest( SubclassPropertyRefTest.suite() );
suite.addTest( NativeSqlSupportSuite.suite() );
suite.addTest( CriteriaQueryTest.suite() );
suite.addTest( SubselectTest.suite() );
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -1,23 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-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;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -1,81 +0,0 @@
-<?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">
-
- <class name="Person">
-
- <id name="id">
- <generator class="hilo"/>
- </id>
-
- <property name="name" length="100"/>
-
- <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>
-
- <property name="userId" column="person_userid" length="8" unique="true"/>
-
- </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
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -1,76 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author gavin
- */
-public class Person {
- private Long id;
- private String name;
- private Address address;
- private String userId;
- private Set accounts = new HashSet();
- /**
- * @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;
- }
-}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefSuite.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,29 @@
+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.complete.CompleteComponentPropertyRefTest;
+import org.hibernate.test.propertyref.component.partial.PartialComponentPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.discrim.SubclassPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.joined.JoinedSubclassPropertyRefTest;
+import org.hibernate.test.propertyref.inheritence.union.UnionSubclassPropertyRefTest;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PropertyRefSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "property-ref suite" );
+ suite.addTest( PropertyRefTest.suite() );
+ suite.addTest( CompleteComponentPropertyRefTest.suite() );
+ suite.addTest( PartialComponentPropertyRefTest.suite() );
+ suite.addTest( SubclassPropertyRefTest.suite() );
+ suite.addTest( JoinedSubclassPropertyRefTest.suite() );
+ suite.addTest( UnionSubclassPropertyRefTest.suite() );
+ return suite;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -1,232 +0,0 @@
-//$Id$
-package org.hibernate.test.propertyref;
-
-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);
- }
-
- 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.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);
- }
-
- protected String[] getMappings() {
- return new String[] { "propertyref/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");
- }
-}
-
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Account.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,48 @@
+//$Id$
+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;
+ }
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Account.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Address.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,73 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Address.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Group.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,23 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Group.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.hbm.xml 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,62 @@
+<?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" table="PROPREF_PERS">
+ <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>
+ </class>
+
+ <class name="Address" table="PROPREF_ADDR">
+ <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" table="PROPREF_ACCT">
+ <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="PROPREF_GRP">
+ <id name="name"/>
+ <set name="users" table="PROPREF_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
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/Person.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,76 @@
+//$Id$
+package org.hibernate.test.propertyref.basic;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author gavin
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private Address address;
+ private String userId;
+ private Set accounts = new HashSet();
+ /**
+ * @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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/Person.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/PropertyRefTest.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,232 @@
+//$Id$
+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 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);
+ }
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/basic/PropertyRefTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Identity.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Mapping.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/complete/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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;
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Account.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Account.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,23 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Account.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Identity.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Identity.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,20 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Identity.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/PersonAccount.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/PersonAccount.hbm.xml 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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>
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Mapping.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/ComponentPropertyRefTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/ComponentPropertyRefTest.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,73 @@
+//$Id$
+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();
+ }
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Person.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/comppropertyref/Person.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,20 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/component/partial/Person.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Account.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Account.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,57 @@
+//$Id$
+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;
+ }
+
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Account.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Customer.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Customer.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,18 @@
+//$Id$
+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;
+ }
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Customer.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Person.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Person.hbm.xml 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Person.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/Person.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,44 @@
+//$Id$
+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;
+ }
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/Person.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/SubclassPropertyRefTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclasspropertyref/SubclassPropertyRefTest.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,64 @@
+//$Id$
+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();
+ }
+
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/discrim/SubclassPropertyRefTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Account.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Account.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,38 @@
+//$Id$
+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;
+ }
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Account.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/BankAccount.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/BankAccount.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,23 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/BankAccount.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/PropertyRefTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/PropertyRefTest.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,70 @@
+//$Id$
+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();
+ }
+
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/JoinedSubclassPropertyRefTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Person.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Person.hbm.xml 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java (from rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Person.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joineduid/Person.java 2006-11-14 13:07:51 UTC (rev 10805)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -0,0 +1,44 @@
+//$Id$
+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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/joined/Person.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Account.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Customer.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.hbm.xml 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/Person.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java 2006-12-05 14:37:32 UTC (rev 10920)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/propertyref/inheritence/union/UnionSubclassPropertyRefTest.java 2006-12-05 14:39:12 UTC (rev 10921)
@@ -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();
+ }
+
+}
[View Less]
18 years, 3 months
Hibernate SVN: r10920 - in trunk/Hibernate3: src/org/hibernate/cfg src/org/hibernate/mapping test/org/hibernate/test test/org/hibernate/test/propertyref test/org/hibernate/test/propertyref/basic test/org/hibernate/test/propertyref/component test/org/hibernate/test/propertyref/component/complete test/org/hibernate/test/propertyref/component/partial test/org/hibernate/test/propertyref/inheritence test/org/hibernate/test/propertyref/inheritence/discrim test/org/hibernate/test/propertyref/in
by hibernate-commits@lists.jboss.org
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/…
[View More]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();
+ }
+
+}
[View Less]
18 years, 3 months