Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/AllTests.java
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/AllTests.java	(revision 10589)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/AllTests.java	(working copy)
@@ -88,6 +88,7 @@
 import org.hibernate.test.mapping.ValueVisitorTest;
 import org.hibernate.test.mappingexception.MappingExceptionTest;
 import org.hibernate.test.mixed.MixedTest;
+import org.hibernate.test.naturalid.EntityNaturalIdTest;
 import org.hibernate.test.naturalid.NaturalIdTest;
 import org.hibernate.test.ondelete.OnDeleteTest;
 import org.hibernate.test.onetomany.OneToManyTest;
@@ -176,6 +177,7 @@
 			suite.addTest( SaveOrUpdateTest.suite() );
 			suite.addTest( MergeTest.suite() );
 			suite.addTest( NaturalIdTest.suite() );
+			suite.addTest( EntityNaturalIdTest.suite() );
 			suite.addTest( ComponentTest.suite() );
 			suite.addTest( ProxyTest.suite() );
 			suite.addTest( VersionTest.suite() );
Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/EntityNaturalIdTest.java
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/EntityNaturalIdTest.java	(revision 0)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/EntityNaturalIdTest.java	(revision 0)
@@ -0,0 +1,105 @@
+package org.hibernate.test.naturalid;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.FetchMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.test.TestCase;
+
+/**
+ * @author Alex Burgel
+ */
+public class EntityNaturalIdTest extends TestCase {
+
+    public EntityNaturalIdTest(String str) {
+        super(str);
+    }
+
+    public void testNaturalIdCheck() throws Exception {
+        Session s = openSession();
+        Transaction t = s.beginTransaction();
+
+        Parent p = new Parent("alex");
+        Child c = new Child("billy", p);
+
+        s.persist(p);
+        s.persist(c);
+        Field name = c.getClass().getDeclaredField("name");
+        name.setAccessible(true);
+        name.set(c, "phil");
+        try {
+            s.flush();
+            fail();
+        }
+        catch (HibernateException he) {}
+        name.set(c, "billy");
+        s.delete(c);
+        s.delete(p);
+        t.commit();
+        s.close();
+    }
+
+    public void testSaveParentWithDetachedChildren() throws Exception {
+        Session s = openSession();
+        Transaction t = s.beginTransaction();
+
+        Parent p = new Parent("alex");
+        Child c = new Child("billy", p);
+
+        s.persist(p);
+        s.persist(c);
+        t.commit();
+        s.close();
+
+        s = openSession();
+        t = s.beginTransaction();
+
+        p = (Parent) s.createCriteria(Parent.class)
+        .add( Restrictions.eq("name", "alex") )
+        .setFetchMode("children", FetchMode.JOIN)
+        .setCacheable(true)
+        .uniqueResult();
+
+        t.commit();
+        s.close();
+
+        s = openSession();
+        t = s.beginTransaction();
+
+        Child c2 = new Child("joey", p);
+        p.getChildren().add(c2);
+
+        s.update(p);
+
+        // this fails if AbstractEntityPersister returns identifiers instead of entities from
+        // AbstractEntityPersister.getNaturalIdSnapshot()
+        s.flush();
+
+        s.delete(p);
+        t.commit();
+        s.close();
+    }
+
+    protected void configure(Configuration cfg) {
+        cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
+        cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
+        cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
+    }
+
+    protected String[] getMappings() {
+        return new String[] { "naturalid/Parent.hbm.xml" };
+    }
+
+    public static Test suite() {
+        return new TestSuite(EntityNaturalIdTest.class);
+    }
+
+}
Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Child.java
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Child.java	(revision 0)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Child.java	(revision 0)
@@ -0,0 +1,20 @@
+//$Id$
+package org.hibernate.test.naturalid;
+
+/**
+ * @author Alex Burgel
+ */
+public class Child {
+	
+	private Long id;
+    private Parent parent;
+	private String name;
+	
+	Child() {}
+
+	public Child(String name, Parent parent) {
+		this.name = name;
+        this.parent = parent;
+	}
+	
+}
Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.java
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.java	(revision 0)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.java	(revision 0)
@@ -0,0 +1,35 @@
+//$Id$
+package org.hibernate.test.naturalid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Alex Burgel
+ */
+public class Parent {
+	
+	private Long id;
+	private String name;
+	private List children = new ArrayList();
+
+	Parent() {}
+
+	public Parent(String name) {
+		this.name = name;
+	}
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List getChildren() {
+        return children;
+    }
+
+    public void setChildren(List children) {
+        this.children = children;
+    }
+
+    
+}
Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.hbm.xml
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.hbm.xml	(revision 0)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/test/org/hibernate/test/naturalid/Parent.hbm.xml	(revision 0)
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+  This mapping illustrates use of <natural-id> with a many-to-one.
+  
+-->
+
+<hibernate-mapping 
+	package="org.hibernate.test.naturalid"
+	default-access="field">
+	
+	<class name="Parent" table="Parent">
+		<id name="id">
+			<generator class="increment"/>
+		</id>
+		
+		<property name="name"/>
+		
+		<bag name="children" inverse="true" cascade="all">
+			<key column="parent" />
+			<one-to-many class="Child" />
+		</bag>
+
+	</class>
+
+	<class name="Child" table="Child">
+		<id name="id">
+			<generator class="increment"/>
+		</id>
+		
+		<natural-id>
+			<many-to-one name="parent" class="Parent" />
+			<property name="name"/>
+		</natural-id>
+	</class>
+	
+</hibernate-mapping>
\ No newline at end of file
Index: C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/src/org/hibernate/persister/entity/AbstractEntityPersister.java	(revision 10589)
+++ C:/Documents and Settings/Alex Burgel/workspace/Hibernate3.2/src/org/hibernate/persister/entity/AbstractEntityPersister.java	(working copy)
@@ -3732,6 +3732,9 @@
 
 					for ( int i = 0; i < naturalIdPropertyCount; i++ ) {
 						snapshot[i] = extractionTypes[i].hydrate( rs, getPropertyAliases( "", naturalIdPropertyIndexes[i] ), session, null );
+						if (extractionTypes[i].isEntityType()) {
+							snapshot[i] = extractionTypes[i].resolve(snapshot[i], session, null);
+						}
 					}
 					return snapshot;
 				}
