I'm attempting to enable Hibernate instrumentation for the JPA entities in a Maven project. Instrumentation seems to work normally on entities with only fields of standard types defined by the Java API (String, BigDecimal, etc.), but when the instrumentation task attempts to work on classes which have fields of types defined by other classes in my project, it fails with the following error:
Code:
[instrument] processing class : com.test.entity.EntityWithCustomTypes; file = C:\Project\Project-ejb\target\classes\com\test\entity\EntityWithCustomTypes.class
Mar 21, 2013 10:00:24 AM org.hibernate.bytecode.internal.javassist.JavassistClassTransformer doTransform
ERROR: HHH000373: Unable to transform class: cannot find com.test.bo.CustomType
I've tried deliberately instrumenting the CustomType class (which shouldn't be necessary); the instrumentation processes it, but it still errors out on EntityWithCustomTypes.
Here is the plugin I'm using in my pom.xml; the project was generated using a JBoss 7 Java EE archetype, and I'm attempting to execute the instrumentation in the EJB module POM:
Code:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<configuration>
<tasks>
<taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath" />
<path refid="maven.compile.classpath" />
<path refid="maven.runtime.classpath" />
<path refid="maven.plugin.classpath" />
<dirset dir="${project.build.outputDirectory}" />
</classpath>
</taskdef>
<instrument verbose="false">
<fileset dir="${project.build.outputDirectory}">
<include name="**/entity/*.class" />
</fileset>
</instrument>
</tasks>
</configuration>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.10.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.15.0-GA</version>
</dependency>
</dependencies>
</plugin>
I can make the error go away by using a newer version of Javassist (3.17.0+), but when I do so, Hibernate seems to ignore my lazy-initialization annotations, which defeats the purpose of instrumentation. I'm assuming that this effect is a result of this bug which forced the Hibernate team to roll back to Javassist 3.15.0 (https://hibernate.atlassian.net/browse/HHH-7923) in the first place: https://hibernate.atlassian.net/browse/HHH-7884.
Is there any way to make my instrumentation use case (JPA classes containing member fields of custom-class types) work with Javassist 3.15.0? Alternatively, is there any current effort to make the instrumentation task work with current versions of Javassist?
(adapted from: http://stackoverflow.com/questions/15550061/hibernate-instrumentation-transform-failure-cannot-find-class-hhh000373)