Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Patch proposal and testcase for HHH-7304 #332

Closed
wants to merge 3 commits into from

2 participants

@pb00068

No description provided.

@brmeyer
Collaborator

Pushed -- thanks for the contribution!

@brmeyer brmeyer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 9, 2012
  1. @pb00068

    HHH-7304 testcase

    pb00068 authored
  2. @pb00068

    HHH-7304 bugfix proposal

    pb00068 authored
  3. @pb00068
This page is out of date. Refresh to see the latest.
View
16 hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java
@@ -72,7 +72,9 @@ protected AbstractEntityInsertAction(
this.isExecuted = false;
this.areTransientReferencesNullified = false;
- handleNaturalIdPreSaveNotifications();
+ if (id != null) {
+ handleNaturalIdPreSaveNotifications();
+ }
}
/**
@@ -193,7 +195,17 @@ protected void handleNaturalIdPreSaveNotifications() {
/**
* Handle sending notifications needed for natural-id after saving
*/
- protected void handleNaturalIdPostSaveNotifications() {
+ public void handleNaturalIdPostSaveNotifications(Serializable id) {
+ if (isEarlyInsert()) {
+ // with early insert, we still need to add a local (transactional) natural id cross-reference
+ getSession().getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
+ getPersister(),
+ id,
+ state,
+ null,
+ CachedNaturalIdValueSource.INSERT
+ );
+ }
// after save, we need to manage the shared cache entries
getSession().getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference(
getPersister(),
View
2  hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java
@@ -127,7 +127,7 @@ public void execute() throws HibernateException {
}
}
- handleNaturalIdPostSaveNotifications();
+ handleNaturalIdPostSaveNotifications(id);
postInsert();
View
2  hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java
@@ -298,6 +298,8 @@ protected Serializable performSaveOrReplicate(
insert.getClass().getName() );
}
id = ( ( EntityIdentityInsertAction ) insert ).getGeneratedId();
+
+ insert.handleNaturalIdPostSaveNotifications(id);
}
markInterceptorDirty( entity, persister, source );
View
27 hibernate-core/src/matrix/java/org/hibernate/test/jpa/naturalid/ClassWithIdentityColumn.java
@@ -0,0 +1,27 @@
+package org.hibernate.test.jpa.naturalid;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.NaturalId;
+
+@Entity
+public class ClassWithIdentityColumn {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+
+ @NaturalId(mutable = true)
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
View
18 hibernate-core/src/matrix/java/org/hibernate/test/jpa/naturalid/MutableNaturalIdTest.java
@@ -27,6 +27,7 @@
import org.hibernate.Session;
import org.hibernate.test.jpa.AbstractJPATest;
+import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -37,7 +38,7 @@
public class MutableNaturalIdTest extends AbstractJPATest {
@Override
protected Class<?>[] getAnnotatedClasses() {
- return new Class[] { Group.class };
+ return new Class[] { Group.class, ClassWithIdentityColumn.class };
}
@Test
@@ -68,4 +69,19 @@ public void testSimpleNaturalIdLoadAccessCacheWithUpdate() {
s.getTransaction().commit();
s.close();
}
+
+ @Test
+ @TestForIssue( jiraKey = "HHH-7304")
+ public void testInLineSynchWithIdentityColumn() {
+ Session s = openSession();
+ s.beginTransaction();
+ ClassWithIdentityColumn e = new ClassWithIdentityColumn();
+ e.setName("Dampf");
+ s.save(e);
+ e.setName("Klein");
+ assertNotNull(session.bySimpleNaturalId(ClassWithIdentityColumn.class).load("Klein"));
+
+ session.getTransaction().rollback();
+ session.close();
+ }
}
Something went wrong with that request. Please try again.