Tuesday, August 25, 2015

Using Eclipselink as JPA 2.1 Implementation on Wildfly 8.x

Enviroment

  • Wildfly 8.2
  • Eclipselink 2.6.0

Adding eclipselink jar on Wildfly

Download eclipselink jar and copy the jar to:
<wildfly-installation</modules/system/layers/base/org/eclipse/persistence/main.

Change the file module.xml from the same folder, adding the eclipselink as resource, as follow:
<resources>
    <resource-root path="jipijapa-eclipselink-1.0.1.Final.jar">
    <resource-root path="eclipselink.jar">
</resources>
Note: Add the value exactly as the jar name, if the jar has the version e.g. eclipselink-2.6.0.Final.jar, the path on the resource must be the same.

Using Eclipselink Provider on persistence.xml

Add the Eclipselink Provider on the persistence.xml.
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

Enabling entity auto-scan

Eclipselink, different from the Hibernate, doesn't scan the entities automatically, they must be added manually on persistence.xml file, e.g.:
<class>com.test.model.Entity1</class>
<class>com.test.model.Entity</class>
To enable the auto-scan on Wildfly, add the following system property on the standalone.xml (or the configuration file that your Wildfly is using):
...
<system-properties>
    <property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl">
<management>
...
Note:  This property can be inserted using the console. To do so, with the Wildfly running execute:
 
jboss-cli.sh --connect '/system-property=eclipselink.archive.factory:add(value=org.jipijapa.eclipselink.JBossArchiveFactoryImpl)'

Enabling Eclipselink logging on console

 To be able to see the SQL generated by the Eclipselink on console, first,  enable the log on persistence.xml:
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true" />

Change the log level of the console on standalone.xml, as follow:
<console-handler name="CONSOLE">
    <level name="TRACE"/>

And add the following logger on standalone.xml:
<logger category="org.eclipse.persistence.sql">
    <level name="DEBUG"/>
</logger> 

More

For more information access:
JPA Reference Guide - Wildfly 8 - Project Documentation

No comments:

Post a Comment