2016-01-12 2 views
0

В WildFly v9 Я пытаюсь использовать транзакцию, управляемую контейнером. Но когда я пытаюсь сохраняющийся сервер выдает эту ошибку:WildFly v9 Невозможно создать EntityManager с SynchronizationType, потому что PersistenceUnit настроен на локальные транзакции ресурсов Ошибка

15:55:54,501 ERROR [stderr] (default task-21) java.lang.IllegalStateException: Unable to create EntityManager with SynchronizationType because PersistenceUnit is configured with resource-local transactions. 

Но в моем файле persistence.xml я использую JTA для операций БД:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" 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"> 
    <persistence-unit name="HospitalAutomation" transaction-type="JTA"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <jta-data-source>java:jboss/datasources/HospitalAutomation</jta-data-source> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Klinikler</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Klinikyerleri</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Doktorlar</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Hastaneler</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Uygunrandevular</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Ilceler</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Iller</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Patients</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Randevusaatleri</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.Takenappointments</class> 
    <class>com.ilkgunel.hastaneotomasyonu.entity.LocalDateConverter</class> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <validation-mode>NONE</validation-mode> 
    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/HospitalAutomation?useUnicode=true&amp;characterEncoding=UTF-8"/> 
     <property name="javax.persistence.jdbc.password" value=""/> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="javax.persistence.schema-generation.database.action" value="create"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

Я использую @PersistenceContext аннотаций в моем классе Java для управления жизненным циклом EntityManager, а мой Java-класс выглядит следующим образом:

/* 


* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package ejb; 

import com.ilkgunel.hastaneotomasyonu.entity.Patients; 
import javax.ejb.Stateless; 
import javax.ejb.TransactionAttribute; 
import javax.ejb.TransactionAttributeType; 
import javax.ejb.TransactionManagement; 
import javax.ejb.TransactionManagementType; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 

/** 
* 
* @author ilkaygunel 
*/ 
@Stateless 
@TransactionManagement(TransactionManagementType.CONTAINER) 
public class SavePatientSessionBean implements SavePatientSessionBeanLocal { 

    @PersistenceContext(unitName = "HospitalAutomation") 
    private EntityManager em; 

    @Override 
    @TransactionAttribute(TransactionAttributeType.REQUIRED) 
    public String savePatient(Patients patients) { 
     try 
     { 
      //em.getTransaction().begin(); 
      em.persist(patients); 
      //em.getTransaction().commit(); 
      return "Bilgileriniz Kaydedildi. Sisteme Giriş Yapıp Randevu Alabilirsiniz"; 
     } catch (Exception e) { 
      System.err.println(e); 
      return "Bilgilerin Kaydı Sırasında Bir Hata Meydana Geldi!"; 
     } 
    } 

} 

ответ

1

Okey. Я нашел решение этой проблемы. Сначала скопируйте eclipselink.jar в свой проект. Для меня это eclipselink-2.5.2.jar. Затем вставьте этот * .jar-файл в папку wildfly/modules/system/layer/base/org/eclipse/persistence/main /. После этого откройте файл modules.xml, который находится в той же папке (основной) и редактировать как это:

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

<!-- 
    ~ JBoss, Home of Professional Open Source. 
    ~ Copyright 2011, Red Hat, Inc., and individual contributors 
    ~ as indicated by the @author tags. See the copyright.txt file in the 
    ~ distribution for a full listing of individual contributors. 
    ~ 
    ~ This is free software; you can redistribute it and/or modify it 
    ~ under the terms of the GNU Lesser General Public License as 
    ~ published by the Free Software Foundation; either version 2.1 of 
    ~ the License, or (at your option) any later version. 
    ~ 
    ~ This software is distributed in the hope that it will be useful, 
    ~ but WITHOUT ANY WARRANTY; without even the implied warranty of 
    ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
    ~ Lesser General Public License for more details. 
    ~ 
    ~ You should have received a copy of the GNU Lesser General Public 
    ~ License along with this software; if not, write to the Free 
    ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 
    ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. 
    --> 

<!-- Represents the EclipseLink module --> 
<module xmlns="urn:jboss:module:1.3" name="org.eclipse.persistence"> 
    <resources> 
     <resource-root path="jipijapa-eclipselink-1.0.1.Final.jar"/> 
     <resource-root path="eclipselink-2.5.2.jar"> 
      <filter> 
        <exclude path="javax/**" /> 
      </filter> 
     </resource-root> 
    </resources> 

    <dependencies> 
     <module name="asm.asm"/> 
     <module name="javax.api"/> 
     <module name="javax.annotation.api"/> 
     <module name="javax.enterprise.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.as.jpa.spi"/> 
     <module name="org.jboss.logging"/> 
     <module name="org.jboss.vfs"/> 
    </dependencies> 
</module> 

Все окей. Теперь запустите проект.

Смежные вопросы