CompositeEnhancer and PersistentAttributesEnhancer do have also potential for similar exception but my problem is first and foremost with EntityEnhancer so here's a patch how I worked around this issue.
@@ -102,7 +102,7 @@
return classPool;
}
- private CtClass loadCtClassFromClass(ClassPool cp, Class<?> aClass) throws IOException {
+ protected CtClass loadCtClassFromClass(ClassPool cp, Class<?> aClass) throws IOException {
String resourceName = aClass.getName().replace( '.', '/' ) + ".class";
InputStream resourceAsStream = aClass.getClassLoader().getResourceAsStream( resourceName );
try {
@@ -6,6 +6,7 @@
*/
package org.hibernate.bytecode.enhance.internal;
+import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -36,8 +37,20 @@
*/
public class EntityEnhancer extends Enhancer {
+ private final CtClass selfDirtinessTrackerCtClass;
+ private final CtClass dirtyTrackerCtClass;
+ private final CtClass collectionTrackerCtClass;
+
public EntityEnhancer(EnhancementContext context) {
super( context );
+ try {
+ this.selfDirtinessTrackerCtClass = loadCtClassFromClass( classPool, SelfDirtinessTracker.class );
+ this.dirtyTrackerCtClass = loadCtClassFromClass( classPool, DirtyTracker.class );
+ this.collectionTrackerCtClass = loadCtClassFromClass( classPool, CollectionTracker.class );
+ }
+ catch (IOException e) {
+ throw new EnhancementException( "Could not prepare Javassist ClassPool", e );
+ }
}
@@ -109,25 +122,20 @@
}
private void addInLineDirtyHandling(CtClass managedCtClass) {
- try {
- managedCtClass.addInterface( classPool.get( SelfDirtinessTracker.class.getName() ) );
+ managedCtClass.addInterface( this.selfDirtinessTrackerCtClass );
FieldWriter.addField(
managedCtClass,
- classPool.get( DirtyTracker.class.getName() ),
+ this.dirtyTrackerCtClass,
EnhancerConstants.TRACKER_FIELD_NAME
);
FieldWriter.addField(
managedCtClass,
- classPool.get( CollectionTracker.class.getName() ),
+ this.collectionTrackerCtClass,
EnhancerConstants.TRACKER_COLLECTION_NAME
);
createDirtyTrackerMethods( managedCtClass );
- }
- catch (NotFoundException nfe) {
- nfe.printStackTrace();
- }
}
private void createDirtyTrackerMethods(CtClass managedCtClass) {
@@ -8,9 +8,12 @@
import javassist.CannotCompileException;
import javassist.CtClass;
-import javassist.NotFoundException;
+
+import java.io.IOException;
+
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
+import org.hibernate.bytecode.enhance.spi.EnhancementException;
import org.hibernate.bytecode.enhance.spi.Enhancer;
import org.hibernate.bytecode.enhance.spi.EnhancerConstants;
import org.hibernate.engine.spi.CompositeOwner;
@@ -23,8 +26,18 @@
*/
public class CompositeEnhancer extends Enhancer {
+ private final CtClass compositeTrackerCtClass;
+ private final CtClass compositeOwnerTrackerCtClass;
+
public CompositeEnhancer(EnhancementContext context) {
super( context );
+ try {
+ this.compositeTrackerCtClass = loadCtClassFromClass( classPool, CompositeTracker.class );
+ this.compositeOwnerTrackerCtClass = loadCtClassFromClass( classPool, CompositeOwnerTracker.class );
+ }
+ catch (IOException e) {
+ throw new EnhancementException( "Could not prepare Javassist ClassPool", e );
+ }
}
public void enhance(CtClass managedCtClass) {
@@ -43,17 +56,11 @@
/* --- */
private void addInLineDirtyHandling(CtClass managedCtClass) {
- try {
- managedCtClass.addInterface( classPool.get( CompositeTracker.class.getName() ) );
+ managedCtClass.addInterface( compositeTrackerCtClass );
- final CtClass compositeCtType = classPool.get( CompositeOwnerTracker.class.getName() );
- FieldWriter.addField( managedCtClass, compositeCtType, EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME );
+ FieldWriter.addField( managedCtClass, compositeOwnerTrackerCtClass, EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME );
createCompositeTrackerMethod( managedCtClass );
- }
- catch (NotFoundException nfe) {
- nfe.printStackTrace();
- }
}
private void createCompositeTrackerMethod(CtClass managedCtClass) {
@@ -6,6 +6,7 @@
*/
package org.hibernate.bytecode.enhance.internal;
+import java.io.IOException;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -31,6 +32,7 @@
import javassist.bytecode.stackmap.MapMaker;
import org.hibernate.Hibernate;
+import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
import org.hibernate.bytecode.enhance.spi.EnhancementException;
import org.hibernate.bytecode.enhance.spi.Enhancer;
@@ -48,9 +50,17 @@
public class PersistentAttributesEnhancer extends Enhancer {
private static final CoreMessageLogger log = CoreLogging.messageLogger( PersistentAttributesEnhancer.class );
+
+ private final CtClass compositeOwnerCtClass;
public PersistentAttributesEnhancer(EnhancementContext context) {
super( context );
+ try {
+ this.compositeOwnerCtClass = loadCtClassFromClass( classPool, CompositeOwner.class );
+ }
+ catch (IOException e) {
+ throw new EnhancementException( "Could not prepare Javassist ClassPool", e );
+ }
}
public void enhance(CtClass managedCtClass) {
@@ -421,7 +431,7 @@
}
- managedCtClass.addInterface( classPool.get( CompositeOwner.class.getName() ) );
+ managedCtClass.addInterface( compositeOwnerCtClass );
if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
|