Quantcast
Channel: BTSoru.com - Bilisim ve Yazilim Teknolojileri Soru/Cevap Platformu - latest questions
Viewing all articles
Browse latest Browse all 4270

WildFly v9 Unable to create EntityManager with SynchronizationType because PersistenceUnit is configured with resource-local transactions Hatası

$
0
0

WildFly Java EE sunucusu üzerinde çalışma yapmak istiyorum. Bir Java sınıfındaki Transaction yönetimini Container'a bırakmak için test yapacağım ama persist işlemi sırasında WildFly

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.

şeklinde bir hata veriyor. Halbuki persistence.xml içinde JTA kullanımı açık.

<?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>

Java sınıfı:

/*
 * 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!";
        }
    }

}

Bu hatayı çözmek için ne yapmam lazım?


Viewing all articles
Browse latest Browse all 4270