1 Reply Latest reply on Dec 1, 2014 10:22 AM by smarlow

    Wildfly 8.1, MySQL and JPA - Eclipselink

    inkimannen

      Hello!

       

      I have set up a datasource on Wildfly and checked if that datasource is working using 'Test connection'.

      The Connection is working.

      Wildfly gives me the following error when trying to use the EntityManager.

      "Unable to create EntityManager with SynchronizationType because PersistenceUnit is configured with resource-local transactions. "

       

      Porting from Glassfish 4 to Wildfly, I have been using Eclipselink - and would still want to use Eclipselink.

       

      My persistence.xml has the following :

      1. <persistence-unit name="myPU" transaction-type="JTA">
      2.     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      3.     <jta-data-source>java:/nfxa</jta-data-source>
      4.     <class>xxxx</class>
      5.     <class>yyyy</class>
      6. </persistence-unit>

       

      My Jboss  'mysql module' has the following -> module.xml

      1. <module xmlns="urn:jboss:module:1.1" name="com.mysql">
      2.             <resources>
      3.                 <resource-root path="mysql-connector-java-5.1.33-bin.jar"/>
      4.             </resources>
      5.             <dependencies>
      6.               <module name="javax.api"/>
      7.               <module name="javax.transaction.api"/>
      8.               <module name="javax.servlet.api" optional="true"/>
      9.     </dependencies>
      10. </module>

       

      The JBoss standalone.xml has this snippet

      1. <datasource jta="true" jndi-name="java:/nfxa" pool-name="NaturDS" enabled="true" use-ccm="false">
      2.                     <connection-url>jdbc:mysql://localhost:3306/<mydatabase></connection-url>
      3.                     <driver>mysql</driver>
      4.                     <pool>
      5.                         <min-pool-size>5</min-pool-size>
      6.                         <max-pool-size>15</max-pool-size>
      7.                     </pool>
      8.                     <security>
      9.                         <user-name>wildfly</user-name>
      10.                         <password>wildfly</password>
      11.                     </security>
      12.                     <validation>
      13.                         <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
      14.                         <validate-on-match>true</validate-on-match>
      15.                         <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
      16.                     </validation>
      17. </datasource>

       

      The code is the following :

      @PersistenceContext(unitName = "myPU")

      private EntityManager em;

       

      The first usage of the Em and where the exception occurs is here :

      Query query = em.createNamedQuery(-my-named-query-);

      I get the exception :

      "Unable to create EntityManager with SynchronizationType because PersistenceUnit is configured with resource-local transactions. "


      I am using maven and I have the following dependencies :

      1. <dependency>
      2.             <groupId>org.eclipse.persistence</groupId>
      3.             <artifactId>eclipselink</artifactId>
      4.             <version>2.5.1</version>
      5.             <type>jar</type>
      6. </dependency>

       

      1. <dependency>
      2.             <groupId>javax</groupId>
      3.             <artifactId>javaee-api</artifactId>
      4.             <version>6.0</version>
      5.             <scope>provided</scope>
      6. </dependency>

       

      Hope that you can give me a hand.

       

      Regards, Ingimar