[hibernate-commits] Hibernate SVN: r11345 - in trunk/Hibernate3: test/org/hibernate/test and 5 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Mar 26 13:24:20 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-03-26 13:24:20 -0400 (Mon, 26 Mar 2007)
New Revision: 11345

Added:
   trunk/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java
   trunk/Hibernate3/test/org/hibernate/test/component/basic/
   trunk/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java
   trunk/Hibernate3/test/org/hibernate/test/component/basic/Employee.java
   trunk/Hibernate3/test/org/hibernate/test/component/basic/Person.java
   trunk/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml
   trunk/Hibernate3/test/org/hibernate/test/component/basic/User.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java
   trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java
Removed:
   trunk/Hibernate3/test/org/hibernate/test/component/ComponentTest.java
   trunk/Hibernate3/test/org/hibernate/test/component/Employee.java
   trunk/Hibernate3/test/org/hibernate/test/component/Person.java
   trunk/Hibernate3/test/org/hibernate/test/component/User.hbm.xml
   trunk/Hibernate3/test/org/hibernate/test/component/User.java
Modified:
   trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
   trunk/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2521 : component cascading

Modified: trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -19,7 +19,6 @@
 import java.util.TimeZone;
 
 import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
 import org.hibernate.MappingException;
 import org.hibernate.classic.Lifecycle;
 import org.hibernate.engine.SessionImplementor;
@@ -501,6 +500,9 @@
 	/**
 	 * Apply the {@link Type#replace} operation across a series of values, as
 	 * long as the corresponding {@link Type} is an association.
+	 * <p/>
+	 * If the corresponding type is a component type, then apply {@link #replaceAssociations}
+	 * accross the component subtypes but do not replace the component value itself.
 	 *
 	 * @param original The source of the state
 	 * @param target The target into which to replace the source values.
@@ -522,10 +524,21 @@
 		Object[] copied = new Object[original.length];
 		for ( int i = 0; i < types.length; i++ ) {
 			if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
-					|| original[i] == BackrefPropertyAccessor.UNKNOWN
-					|| !types[i].isAssociationType() ) {
+					|| original[i] == BackrefPropertyAccessor.UNKNOWN ) {
 				copied[i] = target[i];
 			}
+			else if ( types[i].isComponentType() ) {
+				// need to extract the component values and check for subtype replacements...
+				AbstractComponentType componentType = ( AbstractComponentType ) types[i];
+				Type[] subtypes = componentType.getSubtypes();
+				Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
+				Object[] targetComponentValues = componentType.getPropertyValues( target[i], session );
+				replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
+				copied[i] = target[i];
+			}
+			else if ( !types[i].isAssociationType() ) {
+				copied[i] = target[i];
+			}
 			else {
 				copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
 			}
@@ -533,8 +546,6 @@
 		return copied;
 	}
 
-
-
 	/**
 	 * Determine if any of the given field values are dirty, returning an array containing
 	 * indices of the dirty fields.

Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -23,13 +23,15 @@
 import org.hibernate.test.cascade.RefreshTest;
 import org.hibernate.test.cid.CompositeIdTest;
 import org.hibernate.test.collection.CollectionSuite;
-import org.hibernate.test.component.ComponentTest;
+import org.hibernate.test.component.ComponentSuite;
 import org.hibernate.test.compositeelement.CompositeElementTest;
 import org.hibernate.test.connections.ConnectionsSuite;
 import org.hibernate.test.criteria.CriteriaQueryTest;
 import org.hibernate.test.cuk.CompositePropertyRefTest;
 import org.hibernate.test.cut.CompositeUserTypeTest;
 import org.hibernate.test.deletetransient.DeleteTransientEntityTest;
+import org.hibernate.test.dialect.functional.DialectFunctionalTestsSuite;
+import org.hibernate.test.dialect.unit.DialectUnitTestsSuite;
 import org.hibernate.test.discriminator.DiscriminatorTest;
 import org.hibernate.test.dynamicentity.interceptor.InterceptorDynamicEntityTest;
 import org.hibernate.test.dynamicentity.tuplizer.TuplizerDynamicEntityTest;
@@ -127,8 +129,6 @@
 import org.hibernate.test.version.db.DbVersionTest;
 import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
 import org.hibernate.test.where.WhereTest;
-import org.hibernate.test.dialect.functional.DialectFunctionalTestsSuite;
-import org.hibernate.test.dialect.unit.DialectUnitTestsSuite;
 
 /**
  * @author Gavin King
@@ -171,7 +171,7 @@
 			TestSuite suite = new TestSuite("New tests suite");
 			suite.addTest( OpsSuite.suite() );
 			suite.addTest( NaturalIdTest.suite() );
-			suite.addTest( ComponentTest.suite() );
+			suite.addTest( ComponentSuite.suite() );
 			suite.addTest( ProxyTest.suite() );
 			suite.addTest( VersionTest.suite() );
 			suite.addTest( TimestampTest.suite() );

Added: trunk/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,23 @@
+package org.hibernate.test.component;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.component.basic.ComponentTest;
+import org.hibernate.test.component.cascading.collection.CascadeToComponentCollectionTest;
+import org.hibernate.test.component.cascading.toone.CascadeToComponentAssociationTest;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentSuite {
+	public static Test suite() {
+		TestSuite suite = new TestSuite( "component test suite" );
+		suite.addTest( ComponentTest.suite() );
+		suite.addTest( CascadeToComponentCollectionTest.suite() );
+		suite.addTest( CascadeToComponentAssociationTest.suite() );
+		return suite;
+	}
+}

Deleted: trunk/Hibernate3/test/org/hibernate/test/component/ComponentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/ComponentTest.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/component/ComponentTest.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -1,195 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.Test;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.cfg.Mappings;
-import org.hibernate.criterion.Property;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Formula;
-import org.hibernate.mapping.PersistentClass;
-
-/**
- * @author Gavin King
- */
-public class ComponentTest extends FunctionalTestCase {
-	
-	public ComponentTest(String str) {
-		super(str);
-	}
-
-	public String[] getMappings() {
-		return new String[] { "component/User.hbm.xml" };
-	}
-
-	public void configure(Configuration cfg) {
-		cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
-	}
-
-	public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
-		super.afterConfigurationBuilt( mappings, dialect );
-		// Oracle and Postgres do not have year() functions, so we need to
-		// redefine the 'User.person.yob' formula
-		//
-		// consider temporary until we add the capability to define
-		// mapping foprmulas which can use dialect-registered functions...
-		PersistentClass user = mappings.getClass( User.class.getName() );
-		org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
-		Component component = ( Component ) personProperty.getValue();
-		Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
-
-		SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
-		if ( yearFunction == null ) {
-			// the dialect not know to support a year() function, so rely on the
-			// ANSI SQL extract function
-			f.setFormula( "extract( year from dob )");
-		}
-		else {
-			List args = new ArrayList();
-			args.add( "dob" );
-			f.setFormula( yearFunction.render( args, null ) );
-		}
-	}
-
-	public static Test suite() {
-		return new FunctionalTestClassTestSuite(ComponentTest.class);
-	}
-	
-	public void testUpdateFalse() {
-		getSessions().getStatistics().clear();
-		
-		Session s = openSession();
-		Transaction t = s.beginTransaction();
-		User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
-		s.persist(u);
-		s.flush();
-		u.getPerson().setName("XXXXYYYYY");
-		t.commit();
-		s.close();
-		
-		assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
-		assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
-
-		s = openSession();
-		t = s.beginTransaction();
-		u = (User) s.get(User.class, "gavin");
-		assertEquals( u.getPerson().getName(), "Gavin King" );
-		s.delete(u);
-		t.commit();
-		s.close();
-		
-		assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
-	}
-	
-	public void testComponent() {
-		Session s = openSession();
-		Transaction t = s.beginTransaction();
-		User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
-		s.persist(u);
-		s.flush();
-		u.getPerson().changeAddress("Phipps Place");
-		t.commit();
-		s.close();
-		
-		s = openSession();
-		t = s.beginTransaction();
-		u = (User) s.get(User.class, "gavin");
-		assertEquals( u.getPerson().getAddress(), "Phipps Place" );
-		assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
-		assertEquals( u.getPerson().getYob(), u.getPerson().getDob().getYear()+1900 );
-		u.setPassword("$ecret");
-		t.commit();
-		s.close();
-
-		s = openSession();
-		t = s.beginTransaction();
-		u = (User) s.get(User.class, "gavin");
-		assertEquals( u.getPerson().getAddress(), "Phipps Place" );
-		assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
-		assertEquals( u.getPassword(), "$ecret" );
-		s.delete(u);
-		t.commit();
-		s.close();
-	}
-
-	public void testComponentStateChangeAndDirtiness() {
-		// test for HHH-2366
-		Session s = openSession();
-		s.beginTransaction();
-		User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
-		s.persist( u );
-		s.flush();
-		long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
-		u.getPerson().setAddress( "Austin" );
-		s.flush();
-		assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
-		intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
-		u.getPerson().setAddress( "Cedar Park" );
-		s.flush();
-		assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
-		s.delete( u );
-		s.getTransaction().commit();
-		s.close();
-	}
-
-	public void testComponentQueries() {
-		Session s = openSession();
-		Transaction t = s.beginTransaction();
-		Employee emp = new Employee();
-		emp.setHireDate( new Date() );
-		emp.setPerson( new Person() );
-		emp.getPerson().setName( "steve" );
-		emp.getPerson().setDob( new Date() );
-		s.save( emp );
-
-		s.createQuery( "from Employee e where e.person = :p and 1 = 1 and 2=2" ).setParameter( "p", emp.getPerson() ).list();
-		s.createQuery( "from Employee e where :p = e.person" ).setParameter( "p", emp.getPerson() ).list();
-		s.createQuery( "from Employee e where e.person = ('steve', current_timestamp)" ).list();
-
-		s.delete( emp );
-		t.commit();
-		s.close();
-	}
-	
-	public void testComponentFormulaQuery() {
-		Session s = openSession();
-		Transaction t = s.beginTransaction();
-		s.createQuery("from User u where u.person.yob = 1999").list();
-		s.createCriteria(User.class)
-			.add( Property.forName("person.yob").between( new Integer(1999), new Integer(2002) ) )
-			.list();
-		if ( getDialect().supportsRowValueConstructorSyntax() ) {
-			s.createQuery("from User u where u.person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
-				.setDate("dob", new Date("March 25, 1974")).list();
-			s.createQuery("from User where person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
-				.setDate("dob", new Date("March 25, 1974")).list();
-		}
-		t.commit();
-		s.close();
-	}
-
-	public void testNamedQuery() {
-		Session s = openSession();
-		Transaction t = s.beginTransaction();
-		s.getNamedQuery("userNameIn")
-			.setParameterList( "nameList", new Object[] {"1ovthafew", "turin", "xam"} )
-			.list();
-		t.commit();
-		s.close();
-	}
-
-}
-

Deleted: trunk/Hibernate3/test/org/hibernate/test/component/Employee.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/Employee.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/component/Employee.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -1,38 +0,0 @@
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * todo: describe Employee
- *
- * @author Steve Ebersole
- */
-public class Employee {
-	private Long id;
-	private Person person;
-	private Date hireDate;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public Person getPerson() {
-		return person;
-	}
-
-	public void setPerson(Person person) {
-		this.person = person;
-	}
-
-	public Date getHireDate() {
-		return hireDate;
-	}
-
-	public void setHireDate(Date hireDate) {
-		this.hireDate = hireDate;
-	}
-}

Deleted: trunk/Hibernate3/test/org/hibernate/test/component/Person.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/Person.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/component/Person.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -1,63 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * @author Gavin King
- */
-public class Person {
-	private String name;
-	private Date dob;
-	private String address;
-	private String currentAddress;
-	private String previousAddress;
-	private int yob;
-	Person() {}
-	public Person(String name, Date dob, String address) {
-		this.name = name;
-		this.dob = dob;
-		this.address = address;
-		this.currentAddress = address;
-	}
-	public int getYob() {
-		return yob;
-	}
-	public void setYob(int age) {
-		this.yob = age;
-	}
-	public String getAddress() {
-		return address;
-	}
-	public void setAddress(String address) {
-		this.address = address;
-	}
-	public Date getDob() {
-		return dob;
-	}
-	public void setDob(Date dob) {
-		this.dob = dob;
-	}
-	public String getName() {
-		return name;
-	}
-	public void setName(String name) {
-		this.name = name;
-	}
-	public String getPreviousAddress() {
-		return previousAddress;
-	}
-	public void setPreviousAddress(String previousAddress) {
-		this.previousAddress = previousAddress;
-	}
-	public void changeAddress(String add) {
-		setPreviousAddress( getAddress() );
-		setAddress(add);
-	}
-	public String getCurrentAddress() {
-		return currentAddress;
-	}
-	public void setCurrentAddress(String currentAddress) {
-		this.currentAddress = currentAddress;
-	}
-}

Deleted: trunk/Hibernate3/test/org/hibernate/test/component/User.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/User.hbm.xml	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/component/User.hbm.xml	2007-03-26 17:24:20 UTC (rev 11345)
@@ -1,42 +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">
-
-<!--
-
--->
-
-<hibernate-mapping package="org.hibernate.test.component">
-	
-	<class name="User" table="T_USER">
-		<id name="userName"/>
-		<timestamp name="lastModified"/>
-		<property name="password" not-null="true" optimistic-lock="false"/>
-		<component name="person">
-			<property name="name" update="false" not-null="true"/>
-			<property name="dob" update="false" not-null="true"/>
-			<property name="address"/>
-			<property name="previousAddress" insert="false"/>
-			<property name="yob" formula="year(dob)"/>
-			<property name="currentAddress" 
-				column="address" 
-				insert="false" 
-				update="false"/>
-		</component>
-	</class>
-
-	<class name="Employee" table="T_EMP">
-        <id name="id" type="long" column="ID">
-            <generator class="increment"/>
-        </id>
-        <property name="hireDate" type="date" column="HIRE_DATE"/>
-        <component name="person">
-			<property name="name" update="false" not-null="true"/>
-			<property name="dob" update="false" not-null="true"/>
-		</component>
-	</class>
-	
-	<query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
-	
-</hibernate-mapping>

Deleted: trunk/Hibernate3/test/org/hibernate/test/component/User.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/User.java	2007-03-25 18:24:01 UTC (rev 11344)
+++ trunk/Hibernate3/test/org/hibernate/test/component/User.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -1,44 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * @author Gavin King
- */
-public class User {
-	private String userName;
-	private String password;
-	private Person person;
-	private Date lastModified;
-	User() {}
-	public User(String id, String pw, Person person) {
-		this.userName = id;
-		this.password = pw;
-		this.person = person;
-	}
-	public Date getLastModified() {
-		return lastModified;
-	}
-	public void setLastModified(Date lastModified) {
-		this.lastModified = lastModified;
-	}
-	public String getPassword() {
-		return password;
-	}
-	public void setPassword(String password) {
-		this.password = password;
-	}
-	public Person getPerson() {
-		return person;
-	}
-	public void setPerson(Person person) {
-		this.person = person;
-	}
-	public String getUserName() {
-		return userName;
-	}
-	public void setUserName(String userName) {
-		this.userName = userName;
-	}
-}

Copied: trunk/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/component/ComponentTest.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,194 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.Mappings;
+import org.hibernate.criterion.Property;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Formula;
+import org.hibernate.mapping.PersistentClass;
+
+/**
+ * @author Gavin King
+ */
+public class ComponentTest extends FunctionalTestCase {
+	
+	public ComponentTest(String str) {
+		super(str);
+	}
+
+	public String[] getMappings() {
+		return new String[] { "component/User.hbm.xml" };
+	}
+
+	public void configure(Configuration cfg) {
+		cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+	}
+
+	public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
+		super.afterConfigurationBuilt( mappings, dialect );
+		// Oracle and Postgres do not have year() functions, so we need to
+		// redefine the 'User.person.yob' formula
+		//
+		// consider temporary until we add the capability to define
+		// mapping foprmulas which can use dialect-registered functions...
+		PersistentClass user = mappings.getClass( User.class.getName() );
+		org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
+		Component component = ( Component ) personProperty.getValue();
+		Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
+
+		SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
+		if ( yearFunction == null ) {
+			// the dialect not know to support a year() function, so rely on the
+			// ANSI SQL extract function
+			f.setFormula( "extract( year from dob )");
+		}
+		else {
+			List args = new ArrayList();
+			args.add( "dob" );
+			f.setFormula( yearFunction.render( args, null ) );
+		}
+	}
+
+	public static Test suite() {
+		return new FunctionalTestClassTestSuite(ComponentTest.class);
+	}
+	
+	public void testUpdateFalse() {
+		getSessions().getStatistics().clear();
+		
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+		User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
+		s.persist(u);
+		s.flush();
+		u.getPerson().setName("XXXXYYYYY");
+		t.commit();
+		s.close();
+		
+		assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
+		assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
+
+		s = openSession();
+		t = s.beginTransaction();
+		u = (User) s.get(User.class, "gavin");
+		assertEquals( u.getPerson().getName(), "Gavin King" );
+		s.delete(u);
+		t.commit();
+		s.close();
+		
+		assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
+	}
+	
+	public void testComponent() {
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+		User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
+		s.persist(u);
+		s.flush();
+		u.getPerson().changeAddress("Phipps Place");
+		t.commit();
+		s.close();
+		
+		s = openSession();
+		t = s.beginTransaction();
+		u = (User) s.get(User.class, "gavin");
+		assertEquals( u.getPerson().getAddress(), "Phipps Place" );
+		assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
+		assertEquals( u.getPerson().getYob(), u.getPerson().getDob().getYear()+1900 );
+		u.setPassword("$ecret");
+		t.commit();
+		s.close();
+
+		s = openSession();
+		t = s.beginTransaction();
+		u = (User) s.get(User.class, "gavin");
+		assertEquals( u.getPerson().getAddress(), "Phipps Place" );
+		assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
+		assertEquals( u.getPassword(), "$ecret" );
+		s.delete(u);
+		t.commit();
+		s.close();
+	}
+
+	public void testComponentStateChangeAndDirtiness() {
+		// test for HHH-2366
+		Session s = openSession();
+		s.beginTransaction();
+		User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
+		s.persist( u );
+		s.flush();
+		long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
+		u.getPerson().setAddress( "Austin" );
+		s.flush();
+		assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
+		intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
+		u.getPerson().setAddress( "Cedar Park" );
+		s.flush();
+		assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
+		s.delete( u );
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testComponentQueries() {
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+		Employee emp = new Employee();
+		emp.setHireDate( new Date() );
+		emp.setPerson( new Person() );
+		emp.getPerson().setName( "steve" );
+		emp.getPerson().setDob( new Date() );
+		s.save( emp );
+
+		s.createQuery( "from Employee e where e.person = :p and 1 = 1 and 2=2" ).setParameter( "p", emp.getPerson() ).list();
+		s.createQuery( "from Employee e where :p = e.person" ).setParameter( "p", emp.getPerson() ).list();
+		s.createQuery( "from Employee e where e.person = ('steve', current_timestamp)" ).list();
+
+		s.delete( emp );
+		t.commit();
+		s.close();
+	}
+	
+	public void testComponentFormulaQuery() {
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+		s.createQuery("from User u where u.person.yob = 1999").list();
+		s.createCriteria(User.class)
+			.add( Property.forName("person.yob").between( new Integer(1999), new Integer(2002) ) )
+			.list();
+		if ( getDialect().supportsRowValueConstructorSyntax() ) {
+			s.createQuery("from User u where u.person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
+				.setDate("dob", new Date("March 25, 1974")).list();
+			s.createQuery("from User where person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
+				.setDate("dob", new Date("March 25, 1974")).list();
+		}
+		t.commit();
+		s.close();
+	}
+
+	public void testNamedQuery() {
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+		s.getNamedQuery("userNameIn")
+			.setParameterList( "nameList", new Object[] {"1ovthafew", "turin", "xam"} )
+			.list();
+		t.commit();
+		s.close();
+	}
+
+}
+


Property changes on: trunk/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/Hibernate3/test/org/hibernate/test/component/basic/Employee.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/component/Employee.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/basic/Employee.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/basic/Employee.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,38 @@
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * todo: describe Employee
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+	private Long id;
+	private Person person;
+	private Date hireDate;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Person getPerson() {
+		return person;
+	}
+
+	public void setPerson(Person person) {
+		this.person = person;
+	}
+
+	public Date getHireDate() {
+		return hireDate;
+	}
+
+	public void setHireDate(Date hireDate) {
+		this.hireDate = hireDate;
+	}
+}

Copied: trunk/Hibernate3/test/org/hibernate/test/component/basic/Person.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/component/Person.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/basic/Person.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/basic/Person.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,63 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * @author Gavin King
+ */
+public class Person {
+	private String name;
+	private Date dob;
+	private String address;
+	private String currentAddress;
+	private String previousAddress;
+	private int yob;
+	Person() {}
+	public Person(String name, Date dob, String address) {
+		this.name = name;
+		this.dob = dob;
+		this.address = address;
+		this.currentAddress = address;
+	}
+	public int getYob() {
+		return yob;
+	}
+	public void setYob(int age) {
+		this.yob = age;
+	}
+	public String getAddress() {
+		return address;
+	}
+	public void setAddress(String address) {
+		this.address = address;
+	}
+	public Date getDob() {
+		return dob;
+	}
+	public void setDob(Date dob) {
+		this.dob = dob;
+	}
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getPreviousAddress() {
+		return previousAddress;
+	}
+	public void setPreviousAddress(String previousAddress) {
+		this.previousAddress = previousAddress;
+	}
+	public void changeAddress(String add) {
+		setPreviousAddress( getAddress() );
+		setAddress(add);
+	}
+	public String getCurrentAddress() {
+		return currentAddress;
+	}
+	public void setCurrentAddress(String currentAddress) {
+		this.currentAddress = currentAddress;
+	}
+}


Property changes on: trunk/Hibernate3/test/org/hibernate/test/component/basic/Person.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/component/User.hbm.xml)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,42 @@
+<?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.component">
+	
+	<class name="User" table="T_USER">
+		<id name="userName"/>
+		<timestamp name="lastModified"/>
+		<property name="password" not-null="true" optimistic-lock="false"/>
+		<component name="person">
+			<property name="name" update="false" not-null="true"/>
+			<property name="dob" update="false" not-null="true"/>
+			<property name="address"/>
+			<property name="previousAddress" insert="false"/>
+			<property name="yob" formula="year(dob)"/>
+			<property name="currentAddress" 
+				column="address" 
+				insert="false" 
+				update="false"/>
+		</component>
+	</class>
+
+	<class name="Employee" table="T_EMP">
+        <id name="id" type="long" column="ID">
+            <generator class="increment"/>
+        </id>
+        <property name="hireDate" type="date" column="HIRE_DATE"/>
+        <component name="person">
+			<property name="name" update="false" not-null="true"/>
+			<property name="dob" update="false" not-null="true"/>
+		</component>
+	</class>
+	
+	<query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
+	
+</hibernate-mapping>


Property changes on: trunk/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/Hibernate3/test/org/hibernate/test/component/basic/User.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/component/User.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/basic/User.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/basic/User.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,44 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * @author Gavin King
+ */
+public class User {
+	private String userName;
+	private String password;
+	private Person person;
+	private Date lastModified;
+	User() {}
+	public User(String id, String pw, Person person) {
+		this.userName = id;
+		this.password = pw;
+		this.person = person;
+	}
+	public Date getLastModified() {
+		return lastModified;
+	}
+	public void setLastModified(Date lastModified) {
+		this.lastModified = lastModified;
+	}
+	public String getPassword() {
+		return password;
+	}
+	public void setPassword(String password) {
+		this.password = password;
+	}
+	public Person getPerson() {
+		return person;
+	}
+	public void setPerson(Person person) {
+		this.person = person;
+	}
+	public String getUserName() {
+		return userName;
+	}
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+}


Property changes on: trunk/Hibernate3/test/org/hibernate/test/component/basic/User.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,116 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Iterator;
+import java.util.Locale;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class CascadeToComponentCollectionTest extends FunctionalTestCase {
+
+	public CascadeToComponentCollectionTest(String string) {
+		super( string );
+	}
+
+	public String[] getMappings() {
+		return new String[] { "component/cascading/collection/Mappings.hbm.xml" };
+	}
+
+	public static Test suite() {
+		return new FunctionalTestClassTestSuite( CascadeToComponentCollectionTest.class );
+	}
+
+	public void testMerging() {
+		// step1, we create a definition with one value
+		Session session = openSession();
+		session.beginTransaction();
+		Definition definition = new Definition();
+		Value value1 = new Value( definition );
+		value1.getLocalizedStrings().addString( new Locale( "en_US" ), "hello" );
+		session.persist( definition );
+		session.getTransaction().commit();
+		session.close();
+
+		// step2, we verify that the definition has one value; then we detach it
+		session = openSession();
+		session.beginTransaction();
+		definition = ( Definition ) session.get( Definition.class, definition.getId() );
+		assertEquals( 1, definition.getValues().size() );
+		session.getTransaction().commit();
+		session.close();
+
+		// step3, we add a new value during detachment
+		Value value2 = new Value( definition );
+		value2.getLocalizedStrings().addString( new Locale( "es" ), "hola" );
+
+		// step4 we merge the definition
+		session = openSession();
+		session.beginTransaction();
+		session.merge( definition );
+		session.getTransaction().commit();
+		session.close();
+
+		// step5, final test
+		session = openSession();
+		session.beginTransaction();
+		definition = ( Definition ) session.get( Definition.class, definition.getId() );
+		assertEquals( 2, definition.getValues().size() );
+		Iterator values = definition.getValues().iterator();
+		while ( values.hasNext() ) {
+			assertEquals( 1, ( ( Value ) values.next() ).getLocalizedStrings().getStringsCopy().size() );
+		}
+		session.getTransaction().commit();
+		session.close();
+	}
+
+	public void testMergingOriginallyNullComponent() {
+		// step1, we create a definition with one value, but with a null component
+		Session session = openSession();
+		session.beginTransaction();
+		Definition definition = new Definition();
+		Value value1 = new Value( definition );
+		session.persist( definition );
+		session.getTransaction().commit();
+		session.close();
+
+		// step2, we verify that the definition has one value; then we detach it
+		session = openSession();
+		session.beginTransaction();
+		definition = ( Definition ) session.get( Definition.class, definition.getId() );
+		assertEquals( 1, definition.getValues().size() );
+		session.getTransaction().commit();
+		session.close();
+
+		// step3, we add a new value during detachment
+		( ( Value ) definition.getValues().iterator().next() ).getLocalizedStrings().addString( new Locale( "en_US" ), "hello" );
+		Value value2 = new Value( definition );
+		value2.getLocalizedStrings().addString( new Locale( "es" ), "hola" );
+
+		// step4 we merge the definition
+		session = openSession();
+		session.beginTransaction();
+		session.merge( definition );
+		session.getTransaction().commit();
+		session.close();
+
+		// step5, final test
+		session = openSession();
+		session.beginTransaction();
+		definition = ( Definition ) session.get( Definition.class, definition.getId() );
+		assertEquals( 2, definition.getValues().size() );
+		Iterator values = definition.getValues().iterator();
+		while ( values.hasNext() ) {
+			assertEquals( 1, ( ( Value ) values.next() ).getLocalizedStrings().getStringsCopy().size() );
+		}
+		session.getTransaction().commit();
+		session.close();
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,30 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Definition {
+    private Long id;
+	private Set values = new HashSet();
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Set getValues() {
+		return values;
+	}
+
+	public void setValues(Set values) {
+		this.values = values;
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,26 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class LocalizedStrings {
+	private Map strings = new HashMap();
+
+	public void addString(Locale locale, String value) {
+		strings.put( locale, value );
+	}
+
+	public String getString(Locale locale) {
+		return ( String ) strings.get( locale );
+	}
+
+	public Map getStringsCopy() {
+		return java.util.Collections.unmodifiableMap( strings );
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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.component.cascading.collection">
+
+	<class name="Definition" >
+		<id name="id" type="long" column="ID">
+			<generator class="increment"/>
+		</id>
+		<set name="values" cascade="all-delete-orphan,merge" lazy="false" inverse="true">
+			<key column="DEF_ID" />
+			<one-to-many class="Value"/>
+		</set>
+	</class>
+
+    <class name="Value" >
+		<id name="id" type="long" column="ID">
+			<generator class="increment"/>
+		</id>
+
+		<many-to-one name="definition" class="Definition" column="DEF_ID"/>
+
+        <component name="localizedStrings" class="LocalizedStrings">
+            <map name="strings" access="field" cascade="persist,merge" lazy="false">
+                <key column="VAL_ID" />
+                <map-key type="locale" column="LOC" />
+                <element type="string" column="STR_VAL" />
+            </map>
+		</component>
+
+	</class>
+
+</hibernate-mapping>

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,45 @@
+package org.hibernate.test.component.cascading.collection;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Value {
+	private Long id;
+	private Definition definition;
+	private LocalizedStrings localizedStrings = new LocalizedStrings();
+
+	private Value() {
+	}
+
+	public Value(Definition definition) {
+		this();
+		this.definition = definition;
+		definition.getValues().add( this );
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Definition getDefinition() {
+		return definition;
+	}
+
+	public void setDefinition(Definition definition) {
+		this.definition = definition;
+	}
+
+	public LocalizedStrings getLocalizedStrings() {
+		return localizedStrings;
+	}
+
+	public void setLocalizedStrings(LocalizedStrings localizedStrings) {
+		this.localizedStrings = localizedStrings;
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,63 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+	private Long id;
+	private String street1;
+	private String street2;
+	private String city;
+	private String state;
+	private String zipCode;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getStreet1() {
+		return street1;
+	}
+
+	public void setStreet1(String street1) {
+		this.street1 = street1;
+	}
+
+	public String getStreet2() {
+		return street2;
+	}
+
+	public void setStreet2(String street2) {
+		this.street2 = street2;
+	}
+
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+	public String getState() {
+		return state;
+	}
+
+	public void setState(String state) {
+		this.state = state;
+	}
+
+	public String getZipCode() {
+		return zipCode;
+	}
+
+	public void setZipCode(String zipCode) {
+		this.zipCode = zipCode;
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,71 @@
+package org.hibernate.test.component.cascading.toone;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class CascadeToComponentAssociationTest extends FunctionalTestCase {
+	public CascadeToComponentAssociationTest(String string) {
+		super( string );
+	}
+
+	public String[] getMappings() {
+		return new String[] { "component/cascading/toone/Mappings.hbm.xml" };
+	}
+
+	public static Test suite() {
+		return new FunctionalTestClassTestSuite( CascadeToComponentAssociationTest.class );
+	}
+
+	public void testMerging() {
+		// step1, we create a document with owner
+		Session session = openSession();
+		session.beginTransaction();
+		User user = new User();
+		Document document = new Document();
+		document.setOwner( user );
+		session.persist( document );
+		session.getTransaction().commit();
+		session.close();
+
+		// step2, we verify that the document has owner and that owner has no personal-info; then we detach
+		session = openSession();
+		session.beginTransaction();
+		document = ( Document ) session.get( Document.class, document.getId() );
+		assertNotNull( document.getOwner() );
+		assertNull( document.getOwner().getPersonalInfo() );
+		session.getTransaction().commit();
+		session.close();
+
+		// step3, try to specify the personal-info during detachment
+		Address addr = new Address();
+		addr.setStreet1( "123 6th St" );
+		addr.setCity( "Austin" );
+		addr.setState( "TX" );
+		document.getOwner().setPersonalInfo( new PersonalInfo( addr ) );
+
+		// step4 we merge the document
+		session = openSession();
+		session.beginTransaction();
+		session.merge( document );
+		session.getTransaction().commit();
+		session.close();
+
+		// step5, final test
+		session = openSession();
+		session.beginTransaction();
+		document = ( Document ) session.get( Document.class, document.getId() );
+		assertNotNull( document.getOwner() );
+		assertNotNull( document.getOwner().getPersonalInfo() );
+		assertNotNull( document.getOwner().getPersonalInfo().getHomeAddress() );
+		session.getTransaction().commit();
+		session.close();
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,36 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Document {
+	private Long id;
+	private String location;
+	private User owner;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getLocation() {
+		return location;
+	}
+
+	public void setLocation(String location) {
+		this.location = location;
+	}
+
+	public User getOwner() {
+		return owner;
+	}
+
+	public void setOwner(User owner) {
+		this.owner = owner;
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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.component.cascading.toone">
+
+	<class name="Document" >
+		<id name="id" type="long" column="ID">
+			<generator class="increment"/>
+		</id>
+        <many-to-one name="owner" class="User" cascade="persist,merge,delete"/>
+	</class>
+
+    <class name="User" >
+		<id name="id" type="long" column="ID">
+			<generator class="increment"/>
+		</id>
+        <component name="personalInfo" class="PersonalInfo">
+            <many-to-one name="homeAddress" class="Address" cascade="persist,merge,delete"/>
+		</component>
+	</class>
+
+    <class name="Address">
+        <id name="id" type="long" column="ID">
+			<generator class="increment"/>
+        </id>
+        <property name="street1" type="string" column="STREET1" />
+        <property name="street2" type="string" column="STREET2" />
+        <property name="city" type="string" column="CITY" />
+        <property name="state" type="string" column="STATE" />
+        <property name="zipCode" type="string" column="ZIP_CODE" />
+    </class>
+</hibernate-mapping>

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,25 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PersonalInfo {
+	private Address homeAddress = new Address();
+
+	public PersonalInfo() {
+	}
+
+	public PersonalInfo(Address homeAddress) {
+		this.homeAddress = homeAddress;
+	}
+
+	public Address getHomeAddress() {
+		return homeAddress;
+	}
+
+	public void setHomeAddress(Address homeAddress) {
+		this.homeAddress = homeAddress;
+	}
+}

Added: trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java	2007-03-26 17:24:20 UTC (rev 11345)
@@ -0,0 +1,27 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+	private Long id;
+	private PersonalInfo personalInfo;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public PersonalInfo getPersonalInfo() {
+		return personalInfo;
+	}
+
+	public void setPersonalInfo(PersonalInfo personalInfo) {
+		this.personalInfo = personalInfo;
+	}
+}




More information about the hibernate-commits mailing list