5 Replies Latest reply on Dec 26, 2016 4:29 AM by Anup Dey

    eclipseLink in customModule

    Francesco Gargiulo Newbie

      Hi all,

      I have created the custom module in order to wirte a log into db table.

      Generally I use the eclipselink to manage persistence (jpa), but I'm not able to use eclipselink in custom module, After the call method: Persistence.createEntityManagerFactory(<myPersistenceUnit>), the program seems blocked and the EntityManager object is null.

       

      Please, Could you help me to resolve this incident?

       

      Thanks a lot in advance

        • 1. Re: eclipseLink in customModule
          Panagiotis Chavariotis Novice

          First of all you have to know that EclipseLink is not supported by Red Hat.

          Which version of EAP do you use?

          • 3. Re: eclipseLink in customModule
            Panagiotis Chavariotis Novice

            Can you share the module.xml and the persistence.xml?

            • 4. Re: eclipseLink in customModule
              Francesco Gargiulo Newbie

              Yes module.xml:

               

              <module xmlns="urn:jboss:module:1.1" name="it.xxx.xxx.customLogHandler">

               

               

                  <resources>

                      <resource-root path="customLogHandler.jar"/>

                      <!-- Insert resources here -->

                  </resources>

                <dependencies>

                   <module name="javax.api"/>

                  <module name="javax.transaction.api"/>

                  <module name="org.eclipse.persistence" export="true"/>

                  <module name="javax.persistence.api"/>

                  <module name="org.jboss.logging"/>

                 </dependencies>

              </module>

               

              persistence.xml

               

              <?xml version="1.0" encoding="UTF-8"?>

              <persistence version="2.0"

                xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

               

                <persistence-unit name="MyUnit" transaction-type="JTA">

                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

               

                <class>it.xxx.xxx.loggerhelper.customLogHandler.entity.MyEntity</class>

               

                <properties>

              <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mydb" />

                <property name="eclipselink.target-server" value="JBoss" />

                <property name="eclipselink.target-database" value="MySQL"/>

                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>

                </properties>

                </persistence-unit>

               

              </persistence>

              • 5. Re: eclipseLink in customModule
                Anup Dey Expert

                Hi,

                 

                EclipseLink is not shipped or supported by Red Hat. Red Hat will only give a commercially reasonable effort to help on queries regarding Eclipselink.

                 

                 

                To integrate Eclipselink in EAP 6

                 

                 

                1# Create appropriate directory $JBOSS_HOME/modules/system/layers/base/org/eclipse/persistence/main.

                2# Add EclipseLink JAR into it and create $JBOSS_HOME/modules/system/layers/base/org/eclipse/persistence/main/module.xml with following content.

                 

                ~~~

                <?xml version="1.0" encoding="UTF-8"?> 

                <module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence"> 

                    <resources>

                              <resource-root path="eclipselink.jar"/>  <!-- Point to correct jar version added in module -->

                    </resources> 

                    <dependencies> 

                        <module name="asm.asm"/> 

                        <module name="javax.api"/> 

                        <module name="javax.persistence.api"/> 

                        <module name="javax.transaction.api"/> 

                        <module name="javax.validation.api"/> 

                        <module name="javax.xml.bind.api"/> 

                        <module name="org.antlr"/> 

                        <module name="org.apache.commons.collections"/> 

                        <module name="org.dom4j"/> 

                        <module name="org.javassist"/> 

                        <module name="org.jboss.logging"/> 

                    </dependencies> 

                </module>

                ~~~

                 

                3# Remove any Hibernate specific properties and add following provider and property in persistence.xml.

                 

                ~~~

                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

                ...

                <properties>

                    ...

                    <property name="eclipselink.target-server" value="JBoss"/>

                    ...

                </properties>

                ~~~

                 

                4#Start EAP server to deploy application. Server logs should show successful module dependecy binding to the application, provided DEBUG level logs are enabled for org.jboss.as.jpa.

                 

                ~~~

                13:59:43,477 DEBUG [org.jboss.as.jpa] (MSC service thread 1-1) added org.eclipse.persistence:main dependency to EclipselinkTest.jar

                13:59:43,477 DEBUG [org.jboss.as.jpa] (MSC service thread 1-1) EmployeeService is configured to use persistence provider 'org.eclipse.persistence.jpa.PersistenceProvider', adding an optional dependency on module 'org.eclipse.persistence'

                ~~~

                 

                - To configure static weaving in Eclipselink

                -----------------------------------------------------------

                 

                1#Set up depends on build system.

                2#For Ant, EclipseLink provides an Ant task; the class name is org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask.

                3#For Maven, a plugin to enable "static weaving" is available, although it is not part of the EclipseLink project.

                 

                ~~~

                <plugin> 

                    <groupId>au.com.alderaan</groupId> 

                    <artifactId>eclipselink-staticweave-maven-plugin</artifactId> 

                    <version>1.0.3</version> 

                    <executions> 

                        <execution> 

                            <phase>process-classes</phase> 

                            <goals> 

                                <goal>weave</goal> 

                            </goals> 

                            <configuration> 

                                <logLevel>ALL</logLevel> 

                            </configuration>

                        </execution> 

                    </executions> 

                    <dependencies> 

                        <dependency> 

                            <groupId>org.eclipse.persistence</groupId> 

                            <artifactId>eclipselink</artifactId> 

                            <version>${version.eclipselink}</version> 

                        </dependency> 

                    </dependencies> 

                </plugin> 

                 

                 

                <repository> 

                    <id>EclipseLink</id> 

                    <url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url> 

                </repository> 

                 

                 

                <dependency> 

                    <groupId>org.eclipse.persistence</groupId> 

                    <artifactId>eclipselink</artifactId> 

                    <version>${version.eclipselink}</version> 

                    <scope>provided</scope> 

                </dependency>

                ~~~

                 

                *Note: The "repository" is not necessary if EclipseLink version is 2.5.0 or later, as those releases are available in Maven Central.

                 

                 

                4#Add the following property to persistence.xml.

                 

                ~~~

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

                ~~~

                 

                To make lazy loading working:

                ---------------------------------------

                 

                1#Create custom module org.eclipse.persistence as mentioned in "To integrate Eclipselink in EAP 6" section.

                2#Use the correct provider in persistence.xml

                 

                ~~~

                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

                ~~~

                 

                And remove this property from persistence.xml if present.

                 

                ~~~

                <property name="jboss.as.jpa.providerModule" value="aaa.bbb.eclipselink" /> <!-- value is custom module name that you might have -->

                ~~~

                 

                3#Remove these system properties from standalone.xml if present.

                 

                ~~~

                <property name="eclipselink.target-server" value="JBoss"/>

                <property name="eclipselink.archive.factory" value="CLASS.NAME.OF.YOUR.COPY.OF.JBossArchiveFactoryImpl"/>

                <property name="eclipselink.logging.logger" value="CLASS.NAME.OF.YOUR.COPY.OF.JBossLogger"/>

                ~~~

                 

                4#Configure the static weaving as mentioned in "To configure static weaving in Eclipselink" section.

                 

                For more details See below link:

                How to use EclipseLink with AS7

                 

                Regards,
                Anup