Statically weaving JPA entities for EclipseLink using Maven

EclipseLink provides advanced JPA features such as lazy-loading, change tracking and fetch groups using bytecode weaving. To use bytecode weaving you can either dynamically instrument your entity classes at runtime (via a jvm agent) or use a tool to statically process the .class files after compilation. In this post we will present how to use EclipseLink’s static weaver in a Maven project.

To enable static weaving in a Maven based project we have to add the Eclipselink weaver in the process-classes phase of the Maven’s build life cycle. The process-classes phase happens after the compile phase and allows the post-processing of files generated in compile phase. In our case, the EclipseLink weaver will post-process the .class files produced by the compiler to add extra bytecodes that implement the desired JPA functionality (lazy-loading, etc).

In the below code we use the Maven AntRun plugin to call (via the java ANT task) the command line version of the EclipseLink’s static weaver. Please note that the class name of the weaver is and not as the EclipseLink JPA Extensions wiki page says.

             <java classname=""
                   classpathref="maven.runtime.classpath" fork="true">
               <arg line="-loglevel FINE -persistenceinfo src/main/resources target/classes target/classes"/>

In addition to the pom.xml changes in order to use static weaving in EclipseLink you have to set the eclipselink.weaving property to static in the META-INF/peristence.xml file.

<property name="eclipselink.weaving" value="static" />

For more information about EclipseLink’s static weaving see the How to Configure Static Weaving for JPA Entities section of the Using EclipseLink JPA Extensions wiki page.

Oracle Toplink is now open source

Oracle has released the Toplink O/R mapping framework as open source. They proposed a new persistence project, named Eclipse Persistence Platform (or EclipseLink for short), at the Eclipse Foundation and they are donating the Toplink source code to start the project.

The EclipseLink will be a runtime project offering only libraries and no IDE tooling. Other Eclipse projects, like Dali, offer tooling for JPA and O/R mapping. The project will include the Toplink O/R mapping tools and APIs, a JPA implementation, an OXM framework, a SDO implementation and other persistence related technologies.

Toplink is a very mature and successful product. It is maybe the fist successful O/R mapping product for Java and it is great to see Oracle donating it to the open source community.

For more information see: