Thursday, March 12, 2009

Hibernate bytecode instrumentation (enhance persistent classes) with help of Maven

Is used to enable Hibernate lazy property fetching. "**/model/*" are your persistent classes.

pom.xml:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Instrument domain classes</id>
<configuration>
<tasks>
<taskdef name="instrument"
classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath"/>
<path refid="maven.plugin.classpath"/>
</classpath>
</taskdef>
<instrument verbose="true">
<fileset dir="${project.build.outputDirectory}">
<include name="**/model/*.class"/>
</fileset>
</instrument>
</tasks>
</configuration>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
</dependencies>
</plugin>

3 comments:

  1. I recommend using the javassist version instead; it gave me less problems:

    org.hibernate.tool.instrument.javassist.InstrumentTask

    ReplyDelete
  2. Class "org.hibernate.tool.instrument.cglib.InstrumentTask" is deprecated (see http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/tool/instrument/cglib/InstrumentTask.html)
    Use "org.hibernate.tool.instrument.javassist.InstrumentTask" instead.

    ReplyDelete

Followers