Uploaded image for project: 'DeltaSpike'
  1. DeltaSpike
  2. DELTASPIKE-1300

WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 1.6.1
    • None
    • JPA-Module
    • Wildfly 10.1.0, RESTeasy 3.0.19, CDI 1.2, Ubuntu 16.04

    Description

      Hello,

      In a JAX-RS service, using RestEasy 3.0 on Wildfly 10.1, I have the following producer:

      @ApplicationScoped
      public class EntityManagerProducer
      {
      @PersistenceContext(unitName = "customers")
      private EntityManager em;

      @Produces
      @Default
      @RequestScoped
      public EntityManager createEntityManager()

      { return em; }

      public void dispose(@Disposes @Default EntityManager entityManager)

      { if (entityManager.isOpen()) entityManager.close(); }

      }

      The following end-point:

      @Inject
      private CustomerManagementRepository repo;
      ..............
      @POST
      @Consumes(MediaType.APPLICATION_JSON)
      @Transactional
      public Response createCustomer(Customer customer)

      { Customer newCustomer = repo.saveAndFlushAndRefresh(customer); return Response.created(URI.create("/customers/" + newCustomer.getId())).build(); }

      raises the exception:

      14:57:53,121 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /customer-management/services/customers: org.jboss.resteasy.spi.UnhandledException: javax.persistence.TransactionRequiredException: WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)
      at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:77)
      at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:220)
      ................

      Here above the CustomerManagerRepository is:

      @Repository
      public interface CustomerManagementRepository extends EntityRepository<Customer, BigInteger>

      { public List<Customer> findByFirsName(String firstName); public List<Customer> findByLastName (String lastName); public List<Customer> findByCountry (String country); public List<Customer> findByCity (String city); public List<Customer> findByZip (String zip); public List<Customer> findByState (String state); public List<Customer> findByStreet (String street); }

      I also have the following beans.xml file:

      <?xml version="1.0"?>
      <beans bean-discovery-mode="annotated" version="2.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd">
      <alternatives>
      <class>org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy</class>
      </alternatives>
      </beans>

      What I'm doing wrong here ?

      Attachments

        Activity

          People

            Unassigned Unassigned
            nicolasduminil Nicolas Duminil
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: