HHH-10540 - [enhancer] Add CompositeOwner interface only once
This commit is contained in:
parent
4d9cd0a32d
commit
37b9a0c903
|
@ -433,18 +433,7 @@ public class PersistentAttributesEnhancer extends Enhancer {
|
|||
}
|
||||
|
||||
// make sure to add the CompositeOwner interface
|
||||
managedCtClass.addInterface( classPool.get( CompositeOwner.class.getName() ) );
|
||||
|
||||
if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
|
||||
// if a composite have a embedded field we need to implement the TRACKER_CHANGER_NAME method as well
|
||||
MethodWriter.write(
|
||||
managedCtClass,
|
||||
"public void %1$s(String name) {%n" +
|
||||
" if (%2$s != null) { %2$s.callOwner(\".\" + name); }%n}",
|
||||
EnhancerConstants.TRACKER_CHANGER_NAME,
|
||||
EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME
|
||||
);
|
||||
}
|
||||
addCompositeOwnerInterface( managedCtClass );
|
||||
|
||||
// cleanup previous owner
|
||||
fieldWriter.insertBefore(
|
||||
|
@ -470,6 +459,30 @@ public class PersistentAttributesEnhancer extends Enhancer {
|
|||
);
|
||||
}
|
||||
|
||||
private void addCompositeOwnerInterface(CtClass managedCtClass) throws NotFoundException, CannotCompileException {
|
||||
CtClass compositeOwnerCtClass = managedCtClass.getClassPool().get( CompositeOwner.class.getName() );
|
||||
|
||||
// HHH-10540 only add the interface once
|
||||
for ( CtClass i : managedCtClass.getInterfaces() ) {
|
||||
if ( i.subclassOf( compositeOwnerCtClass ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
managedCtClass.addInterface( compositeOwnerCtClass );
|
||||
|
||||
if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
|
||||
// if a composite have a embedded field we need to implement the TRACKER_CHANGER_NAME method as well
|
||||
MethodWriter.write(
|
||||
managedCtClass,
|
||||
"public void %1$s(String name) {%n" +
|
||||
" if (%2$s != null) { %2$s.callOwner(\".\" + name); }%n}",
|
||||
EnhancerConstants.TRACKER_CHANGER_NAME,
|
||||
EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void enhanceAttributesAccess(
|
||||
CtClass managedCtClass,
|
||||
IdentityHashMap<String, PersistentAttributeAccessMethods> attributeDescriptorMap) {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.test.bytecode.enhancement.dirty;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -36,6 +37,9 @@ public class SimpleEntity {
|
|||
@Embedded
|
||||
private Address address;
|
||||
|
||||
@Embedded
|
||||
private Address address2;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue