Author: steve.ebersole(a)jboss.com
Date: 2010-10-06 13:39:33 -0400 (Wed, 06 Oct 2010)
New Revision: 20780
Modified:
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/MedicalHistory.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/Person.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/PersonId.java
Log:
HHH-5629 - Inconsistent consistency checks for entities already found in session
Modified:
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java 2010-10-06
11:19:32 UTC (rev 20779)
+++
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java 2010-10-06
17:39:33 UTC (rev 20780)
@@ -99,13 +99,13 @@
);
}
+ final Class idClass = persister.getIdentifierType().getReturnedClass();
if ( persister.getIdentifierType().isComponentType() && EntityMode.DOM4J ==
event.getSession().getEntityMode() ) {
// skip this check for composite-ids relating to dom4j entity-mode;
// alternatively, we could add a check to make sure the incoming id value is
// an instance of Element...
}
else {
- Class idClass = persister.getIdentifierType().getReturnedClass();
if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
// we may have the kooky jpa requirement of allowing find-by-id where
// "id" is the "simple pk value" of a dependent objects parent.
This
@@ -542,7 +542,8 @@
}
}
if ( options.isAllowNulls() ) {
- EntityPersister persister = event.getSession().getFactory().getEntityPersister(
event.getEntityClassName() );
+// EntityPersister persister = event.getSession().getFactory().getEntityPersister(
event.getEntityClassName() );
+ EntityPersister persister = event.getSession().getFactory().getEntityPersister(
keyToLoad.getEntityName() );
if ( ! persister.isInstance( old, event.getSession().getEntityMode() ) ) {
return INCONSISTENT_RTN_CLASS_MARKER;
}
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java 2010-10-06
11:19:32 UTC (rev 20779)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java 2010-10-06
17:39:33 UTC (rev 20780)
@@ -8,33 +8,67 @@
* @author Emmanuel Bernard
*/
public class DerivedIdentityIdClassParentSameIdTypeIdClassDepTest extends TestCase {
-
+ private static final String FIRST_NAME = "Emmanuel";
+ private static final String LAST_NAME = "Bernard";
+
public void testOneToOneExplicitJoinColumn() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1",
getCfg() ) );
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2",
getCfg() ) );
assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory",
"firstname", getCfg() ) );
- Person e = new Person();
- e.firstName = "Emmanuel";
- e.lastName = "Bernard";
- Session s = openSession( );
+
+ Session s = openSession();
s.getTransaction().begin();
+ Person e = new Person( FIRST_NAME, LAST_NAME );
s.persist( e );
- MedicalHistory d = new MedicalHistory();
- d.patient = e;
+ MedicalHistory d = new MedicalHistory( e );
s.persist( d );
s.flush();
- s.clear();
- PersonId pId = new PersonId();
- pId.firstName = e.firstName;
- pId.lastName = e.lastName;
- d = (MedicalHistory) s.get( MedicalHistory.class, pId);
- assertEquals( pId.firstName, d.patient.firstName );
- s.delete( d );
- s.delete( d.patient );
- s.getTransaction().rollback();
+ s.refresh( d );
+ s.getTransaction().commit();
s.close();
+
+ s = openSession();
+ s.getTransaction().begin();
+ PersonId pId = new PersonId( FIRST_NAME, LAST_NAME );
+ MedicalHistory d2 = (MedicalHistory) s.get( MedicalHistory.class, pId );
+ Person p2 = (Person) s.get( Person.class, pId );
+ assertEquals( pId.firstName, d2.patient.firstName );
+ assertEquals( pId.firstName, p2.firstName );
+ s.delete( d2 );
+ s.delete( p2 );
+ s.getTransaction().commit();
+ s.close();
}
+ public void testTckLikeBehavior() throws Exception {
+ assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1",
getCfg() ) );
+ assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2",
getCfg() ) );
+ assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory",
"firstname", getCfg() ) );
+
+ Session s = openSession();
+ s.getTransaction().begin();
+ Person e = new Person( FIRST_NAME, LAST_NAME );
+ s.persist( e );
+ MedicalHistory d = new MedicalHistory( e );
+ s.persist( d );
+ s.flush();
+ s.refresh( d );
+ s.getTransaction().commit();
+
+ // NOTE THAT WE LEAVE THE SESSION OPEN!
+
+ s.getTransaction().begin();
+ PersonId pId = new PersonId( FIRST_NAME, LAST_NAME );
+ MedicalHistory d2 = (MedicalHistory) s.get( MedicalHistory.class, pId );
+ Person p2 = (Person) s.get( Person.class, pId );
+ assertEquals( pId.firstName, d2.patient.firstName );
+ assertEquals( pId.firstName, p2.firstName );
+ s.delete( d2 );
+ s.delete( p2 );
+ s.getTransaction().commit();
+ s.close();
+ }
+
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/MedicalHistory.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/MedicalHistory.java 2010-10-06
11:19:32 UTC (rev 20779)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/MedicalHistory.java 2010-10-06
17:39:33 UTC (rev 20780)
@@ -21,4 +21,11 @@
})
@OneToOne
Person patient;
+
+ public MedicalHistory() {
+ }
+
+ public MedicalHistory(Person patient) {
+ this.patient = patient;
+ }
}
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/Person.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/Person.java 2010-10-06
11:19:32 UTC (rev 20779)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/Person.java 2010-10-06
17:39:33 UTC (rev 20780)
@@ -13,4 +13,12 @@
public class Person {
@Id String firstName;
@Id String lastName;
+
+ public Person() {
+ }
+
+ public Person(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
}
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/PersonId.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/PersonId.java 2010-10-06
11:19:32 UTC (rev 20779)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/PersonId.java 2010-10-06
17:39:33 UTC (rev 20780)
@@ -8,4 +8,12 @@
public class PersonId implements Serializable {
String firstName;
String lastName;
+
+ public PersonId() {
+ }
+
+ public PersonId(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
}
Show replies by date