HHH-10562 : ManagedEntity linked list broken when non-associated enhanced entity is evicted
(cherry picked from commit 7ed51f44dd
)
This commit is contained in:
parent
bfc4289f12
commit
d2ed801ea8
|
@ -181,10 +181,13 @@ public class EntityEntryContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we could not resolve it, just return (it was not associated with this context)
|
// if we could not resolve it, just return (it was not associated with this context)
|
||||||
if ( managedEntity == null ) {
|
if ( managedEntity == null || managedEntity.$$_hibernate_getEntityEntry() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: should dirty be set to true only if managedEntity is associtated with this context
|
||||||
|
// (instead of setting it at the top of this method)?
|
||||||
|
|
||||||
// prepare for re-linking...
|
// prepare for re-linking...
|
||||||
final ManagedEntity previous = managedEntity.$$_hibernate_getPreviousManagedEntity();
|
final ManagedEntity previous = managedEntity.$$_hibernate_getPreviousManagedEntity();
|
||||||
final ManagedEntity next = managedEntity.$$_hibernate_getNextManagedEntity();
|
final ManagedEntity next = managedEntity.$$_hibernate_getNextManagedEntity();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.bytecode.enhancement;
|
package org.hibernate.test.bytecode.enhancement;
|
||||||
|
|
||||||
|
import org.hibernate.test.bytecode.enhancement.eviction.EvictionTestTask;
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||||
|
@ -61,6 +62,11 @@ public class EnhancerTest extends BaseUnitTestCase {
|
||||||
EnhancerTestUtils.runEnhancerTestTask( DirtyTrackingTestTask.class );
|
EnhancerTestUtils.runEnhancerTestTask( DirtyTrackingTestTask.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEviction() {
|
||||||
|
EnhancerTestUtils.runEnhancerTestTask( EvictionTestTask.class );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssociation() {
|
public void testAssociation() {
|
||||||
EnhancerTestUtils.runEnhancerTestTask( OneToOneAssociationTestTask.class );
|
EnhancerTestUtils.runEnhancerTestTask( OneToOneAssociationTestTask.class );
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* 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.eviction;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.engine.spi.ManagedEntity;
|
||||||
|
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class EvictionTestTask extends AbstractEnhancerTestTask {
|
||||||
|
|
||||||
|
|
||||||
|
public Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class<?>[] {Parent.class};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prepare() {
|
||||||
|
Configuration cfg = new Configuration();
|
||||||
|
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||||
|
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
|
||||||
|
super.prepare( cfg );
|
||||||
|
|
||||||
|
// Create a Parent
|
||||||
|
Session s = getFactory().openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
|
||||||
|
Parent p = new Parent();
|
||||||
|
p.setName( "PARENT" );
|
||||||
|
s.persist( p );
|
||||||
|
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute() {
|
||||||
|
// Delete the Parent
|
||||||
|
Session s = getFactory().openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
|
||||||
|
.setParameter( "name", "PARENT" )
|
||||||
|
.uniqueResult();
|
||||||
|
assertTyping( ManagedEntity.class, loadedParent );
|
||||||
|
ManagedEntity managedParent = (ManagedEntity) loadedParent;
|
||||||
|
// before eviction
|
||||||
|
assertNotNull( managedParent.$$_hibernate_getEntityInstance() );
|
||||||
|
assertNotNull( managedParent.$$_hibernate_getEntityEntry() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getPreviousManagedEntity() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getNextManagedEntity() );
|
||||||
|
|
||||||
|
assertTrue( s.contains( managedParent ) );
|
||||||
|
s.evict( managedParent );
|
||||||
|
|
||||||
|
// after eviction
|
||||||
|
assertFalse( s.contains( managedParent ) );
|
||||||
|
assertNotNull( managedParent.$$_hibernate_getEntityInstance() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getEntityEntry() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getPreviousManagedEntity() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getNextManagedEntity() );
|
||||||
|
|
||||||
|
// evict again
|
||||||
|
s.evict( managedParent );
|
||||||
|
|
||||||
|
assertFalse( s.contains( managedParent ) );
|
||||||
|
assertNotNull( managedParent.$$_hibernate_getEntityInstance() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getEntityEntry() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getPreviousManagedEntity() );
|
||||||
|
assertNull( managedParent.$$_hibernate_getNextManagedEntity() );
|
||||||
|
|
||||||
|
s.delete( managedParent );
|
||||||
|
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanup() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.hibernate.test.bytecode.enhancement.eviction;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by barreiro on 12/9/15.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Parent {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue