4 Replies Latest reply on Nov 5, 2019 3:39 PM by Scott Marlow

    About “WFLYJPA0060: Transaction is required”

    Alexey Usharovski Newbie

      Not sure if here is right place for this question but I simply want to know more about that.

       

      I'm using JPA in Wildfly application.

      If I use datasource from the application server with this persistence.xml all is fine

      <?xml version="1.0" encoding="UTF-8"?> 
      <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
      version="2.1"> 
         <persistence-unit name="ds" transaction-type="JTA">
            <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
               <jta-data-source>
      java:/jboss/datasources/MySQLDS</jta-data-source>
              
      <properties>
                   .... some options
              
      </properties>
         </persistence-unit>
      </persistence>

      But if I'm trying to use it with in application DB connection properties I got "WFLYJPA0060: Transaction is required" exception.

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
      version="2.1"> 
         <persistence-unit name="ds" transaction-type="JTA">
            <provider>
      org.hibernate.jpa.HibernatePersistenceProvider</provider>
            <properties>
              
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/javaee_test_db?createDatabaseIfNotExist=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"/>
               <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="root"/>
              
      <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/> 
               .... some options
            </properties>
        
      </persistence-unit>
      </persistence>

      Why it works this way? What should I do to fix?