HHH-11293 - Consider enhanced entities with collections as being not unequivocally non-dirty

This commit is contained in:
Craig Andrews 2016-12-02 12:43:39 -05:00 committed by Vlad Mihalcea
parent 67f7be9a80
commit 916a93ada5
4 changed files with 118 additions and 5 deletions

View File

@ -342,7 +342,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
@SuppressWarnings( {"SimplifiableIfStatement"})
private boolean isUnequivocallyNonDirty(Object entity) {
if ( entity instanceof SelfDirtinessTracker ) {
return ! ( (SelfDirtinessTracker) entity ).$$_hibernate_hasDirtyAttributes();
return ! persister.hasCollections() && ! ( (SelfDirtinessTracker) entity ).$$_hibernate_hasDirtyAttributes();
}
final CustomEntityDirtinessStrategy customEntityDirtinessStrategy =

View File

@ -8,22 +8,20 @@ package org.hibernate.test.bytecode.enhancement;
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.test.bytecode.enhancement.association.InheritedAttributeAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.group.LazyGroupUpdateTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.group.SimpleLazyGroupUpdateTestTask;
import org.hibernate.test.bytecode.enhancement.otherentityentrycontext.OtherEntityEntryContextTestTask;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.bytecode.enhancement.access.MixedAccessTestTask;
import org.hibernate.test.bytecode.enhancement.association.InheritedAttributeAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.association.ManyToManyAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.association.OneToManyAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.association.OneToOneAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.basic.BasicEnhancementTestTask;
import org.hibernate.test.bytecode.enhancement.basic.HHH9529TestTask;
import org.hibernate.test.bytecode.enhancement.cascade.CascadeDeleteTestTask;
import org.hibernate.test.bytecode.enhancement.dirty.DirtyTrackingCollectionTestTask;
import org.hibernate.test.bytecode.enhancement.dirty.DirtyTrackingTestTask;
import org.hibernate.test.bytecode.enhancement.eviction.EvictionTestTask;
import org.hibernate.test.bytecode.enhancement.extended.ExtendedAssociationManagementTestTasK;
@ -44,6 +42,8 @@ import org.hibernate.test.bytecode.enhancement.lazy.LazyProxyOnEnhancedEntityTes
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicFieldAccessTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicPropertyAccessTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.group.LazyGroupAccessTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.group.LazyGroupUpdateTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.group.SimpleLazyGroupUpdateTestTask;
import org.hibernate.test.bytecode.enhancement.lazyCache.InitFromCacheTestTask;
import org.hibernate.test.bytecode.enhancement.mapped.MappedSuperclassTestTask;
import org.hibernate.test.bytecode.enhancement.merge.CompositeMergeTestTask;
@ -228,6 +228,12 @@ public class EnhancerTest extends BaseUnitTestCase {
EnhancerTestUtils.runEnhancerTestTask( LazyBasicFieldNotInitializedTestTask.class );
}
@Test
@TestForIssue( jiraKey = "HHH-11293")
public void testDirtyCollection() {
EnhancerTestUtils.runEnhancerTestTask( DirtyTrackingCollectionTestTask.class );
}
@Test
public void testInitFromCache() {
EnhancerTestUtils.runEnhancerTestTask( InitFromCacheTestTask.class );

View File

@ -0,0 +1,66 @@
/*
* 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.bytecode.enhancement.dirty;
import java.util.ArrayList;
import java.util.Arrays;
import org.hibernate.cfg.Configuration;
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
/**
* @author Luis Barreiro
*/
public class DirtyTrackingCollectionTestTask extends AbstractEnhancerTestTask {
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {ParentChildEntity.class};
}
public void prepare() {
super.prepare( new Configuration() );
}
public void execute() {
doInJPA( this::getFactory, entityManager -> {
ParentChildEntity entity = new ParentChildEntity();
entity.setId( 1L );
entity.setSomeStrings( new ArrayList<>( Arrays.asList( "a", "b", "c") ) );
entityManager.persist( entity );
} );
doInJPA( this::getFactory, entityManager -> {
ParentChildEntity entity = entityManager.find( ParentChildEntity.class, 1L );
entity.getSomeStrings().clear();
} );
doInJPA( this::getFactory, entityManager -> {
ParentChildEntity entity = entityManager.find( ParentChildEntity.class, 1L );
assertEquals(0, entity.getSomeStrings().size());
entity.getSomeStrings().add( "d" );
} );
doInJPA( this::getFactory, entityManager -> {
ParentChildEntity entity = entityManager.find( ParentChildEntity.class, 1L );
assertEquals(1, entity.getSomeStrings().size());
entity.setSomeStrings( new ArrayList<>() );
} );
doInJPA( this::getFactory, entityManager -> {
ParentChildEntity entity = entityManager.find( ParentChildEntity.class, 1L );
assertEquals(0, entity.getSomeStrings().size());
} );
}
protected void cleanup() {
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.bytecode.enhancement.dirty;
import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author Vlad Mihalcea
*/
@Entity
public class ParentChildEntity {
@Id
private Long id;
@ElementCollection
private List<String> someStrings;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getSomeStrings() {
return someStrings;
}
public void setSomeStrings(List<String> someStrings) {
this.someStrings = someStrings;
}
}