HHH-9529 - [enhancer] check that the field being accessed belongs to the entity being enhanced
This commit is contained in:
parent
4793ca30a2
commit
1568f89426
|
@ -480,6 +480,12 @@ public class PersistentAttributesEnhancer extends Enhancer {
|
|||
if ( op != Opcode.PUTFIELD && op != Opcode.GETFIELD ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// only transform access to fields of the entity being enhanced
|
||||
if ( !managedCtClass.getName().equals( constPool.getFieldrefClassName( itr.u16bitAt( index + 1 ) ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String fieldName = constPool.getFieldrefName( itr.u16bitAt( index + 1 ) );
|
||||
final PersistentAttributeAccessMethods attributeMethods = attributeDescriptorMap.get( fieldName );
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.hibernate.test.bytecode.enhancement.association.ManyToManyAssociation
|
|||
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.dirty.DirtyTrackingTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.field.FieldAccessBidirectionalTestTasK;
|
||||
import org.hibernate.test.bytecode.enhancement.field.FieldAccessEnhancementTestTask;
|
||||
|
@ -30,10 +31,10 @@ import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicPropertyAcces
|
|||
import org.hibernate.test.bytecode.enhancement.lazy.group.LazyGroupAccessTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.lazyCache.InitFromCacheTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.merge.CompositeMergeTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.pk.EmbeddedPKTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.ondemandload.LazyCollectionWithClearedSessionTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.ondemandload.LazyCollectionWithClosedSessionTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.ondemandload.LazyEntityLoadingWithClosedSessionTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.pk.EmbeddedPKTestTask;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -46,6 +47,12 @@ public class EnhancerTest extends BaseUnitTestCase {
|
|||
EnhancerTestUtils.runEnhancerTestTask( BasicEnhancementTestTask.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9529" )
|
||||
public void testFieldHHH9529() {
|
||||
EnhancerTestUtils.runEnhancerTestTask( HHH9529TestTask.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirty() {
|
||||
EnhancerTestUtils.runEnhancerTestTask( DirtyTrackingTestTask.class );
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.basic;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapsId;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
public class HHH9529TestTask extends AbstractEnhancerTestTask {
|
||||
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {Parent.class, Child.class, ChildKey.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 );
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
}
|
||||
|
||||
@Entity
|
||||
public class Parent {
|
||||
@Id
|
||||
String id;
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
public class ChildKey implements Serializable {
|
||||
String parent;
|
||||
String type;
|
||||
}
|
||||
|
||||
@Entity
|
||||
public class Child {
|
||||
@EmbeddedId
|
||||
ChildKey id;
|
||||
|
||||
@MapsId("parent")
|
||||
@ManyToOne
|
||||
Parent parent;
|
||||
|
||||
public String getfieldOnChildKeyParent() {
|
||||
// Note that there are two GETFIELD ops here, one on the field 'id' that should be enhanced and another
|
||||
// on the field 'parent' that may be or not (depending if 'extended enhancement' is enabled)
|
||||
|
||||
// Either way, the field 'parent' on ChildKey should not be confused with the field 'parent' on Child
|
||||
|
||||
return id.parent;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue