HHH-13256 - Fix the fieldsPreUpdateNeeded property index allocation in AbstractEntityPersister#update
This commit is contained in:
parent
69af6caa95
commit
462e171ee3
|
@ -421,6 +421,12 @@ public final class ArrayHelper {
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] trim(int[] from, int length) {
|
||||||
|
int[] trimmed = new int[length];
|
||||||
|
System.arraycopy( from, 0, trimmed, 0, length );
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
@AllowSysOut
|
@AllowSysOut
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
int[] batchSizes = ArrayHelper.getBatchSizes( 32 );
|
int[] batchSizes = ArrayHelper.getBatchSizes( 32 );
|
||||||
|
|
|
@ -3546,6 +3546,7 @@ public abstract class AbstractEntityPersister
|
||||||
int valueGenerationStrategiesSize = valueGenerationStrategies.length;
|
int valueGenerationStrategiesSize = valueGenerationStrategies.length;
|
||||||
if ( valueGenerationStrategiesSize != 0 ) {
|
if ( valueGenerationStrategiesSize != 0 ) {
|
||||||
int[] fieldsPreUpdateNeeded = new int[valueGenerationStrategiesSize];
|
int[] fieldsPreUpdateNeeded = new int[valueGenerationStrategiesSize];
|
||||||
|
int count = 0;
|
||||||
for ( int i = 0; i < valueGenerationStrategiesSize; i++ ) {
|
for ( int i = 0; i < valueGenerationStrategiesSize; i++ ) {
|
||||||
if ( valueGenerationStrategies[i] != null && valueGenerationStrategies[i].getGenerationTiming()
|
if ( valueGenerationStrategies[i] != null && valueGenerationStrategies[i].getGenerationTiming()
|
||||||
.includesUpdate() ) {
|
.includesUpdate() ) {
|
||||||
|
@ -3554,7 +3555,7 @@ public abstract class AbstractEntityPersister
|
||||||
object
|
object
|
||||||
);
|
);
|
||||||
setPropertyValue( object, i, fields[i] );
|
setPropertyValue( object, i, fields[i] );
|
||||||
fieldsPreUpdateNeeded[i] = i;
|
fieldsPreUpdateNeeded[count++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if ( fieldsPreUpdateNeeded.length != 0 ) {
|
// if ( fieldsPreUpdateNeeded.length != 0 ) {
|
||||||
|
@ -3567,7 +3568,7 @@ public abstract class AbstractEntityPersister
|
||||||
// // no dirty fields and no dirty collections so no update needed ???
|
// // no dirty fields and no dirty collections so no update needed ???
|
||||||
// }
|
// }
|
||||||
if ( fieldsPreUpdateNeeded.length != 0 && dirtyFields != null ) {
|
if ( fieldsPreUpdateNeeded.length != 0 && dirtyFields != null ) {
|
||||||
dirtyFields = ArrayHelper.join( fieldsPreUpdateNeeded, dirtyFields );
|
dirtyFields = ArrayHelper.join( dirtyFields, ArrayHelper.trim( fieldsPreUpdateNeeded, count ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.type;
|
||||||
|
|
||||||
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
|
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
||||||
import org.hibernate.tuple.NonIdentifierAttribute;
|
import org.hibernate.tuple.NonIdentifierAttribute;
|
||||||
|
|
||||||
|
@ -325,9 +326,7 @@ public class TypeHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int[] trimmed = new int[count];
|
return ArrayHelper.trim(results, count);
|
||||||
System.arraycopy( results, 0, trimmed, 0, count );
|
|
||||||
return trimmed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class InMemoryCreationTimestampNullableColumnTest extends BaseEntityManag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "Person")
|
@Entity(name = "Person")
|
||||||
public class Person {
|
public static class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -64,7 +64,6 @@ public class InMemoryCreationTimestampNullableColumnTest extends BaseEntityManag
|
||||||
public void setCreationDate(Date creationDate) {
|
public void setCreationDate(Date creationDate) {
|
||||||
this.creationDate = creationDate;
|
this.creationDate = creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.annotations;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.NaturalId;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vlad Mihalcea
|
||||||
|
*/
|
||||||
|
@TestForIssue(jiraKey = "HHH-13256")
|
||||||
|
public class InMemoryUpdateTimestampTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class<?>[] {
|
||||||
|
Person.class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
Person person = new Person();
|
||||||
|
person.setId( 1L );
|
||||||
|
person.setFirstName( "Jon" );
|
||||||
|
person.setLastName( "Doe" );
|
||||||
|
entityManager.persist( person );
|
||||||
|
|
||||||
|
entityManager.flush();
|
||||||
|
Assert.assertNotNull( person.getUpdatedOn() );
|
||||||
|
} );
|
||||||
|
|
||||||
|
AtomicReference<Date> beforeTimestamp = new AtomicReference<>();
|
||||||
|
|
||||||
|
sleep( 1 );
|
||||||
|
|
||||||
|
Person _person = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
Person person = entityManager.find( Person.class, 1L );
|
||||||
|
beforeTimestamp.set( person.getUpdatedOn() );
|
||||||
|
person.setLastName( "Doe Jr." );
|
||||||
|
|
||||||
|
return person;
|
||||||
|
} );
|
||||||
|
|
||||||
|
assertTrue( _person.getUpdatedOn().after( beforeTimestamp.get() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "Person")
|
||||||
|
public static class Person {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@UpdateTimestamp
|
||||||
|
private Date updatedOn;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedOn() {
|
||||||
|
return updatedOn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue