Nicolas Duminil created DELTASPIKE-1300:
-------------------------------------------

             Summary: WFLYJPA0060: Transaction is required to perform this 
operation (either use a transaction or extended persistence context)
                 Key: DELTASPIKE-1300
                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1300
             Project: DeltaSpike
          Issue Type: Bug
          Components: JPA-Module
    Affects Versions: 1.6.1
         Environment: Wildfly 10.1.0, RESTeasy 3.0.19, CDI 1.2, Ubuntu 16.04
            Reporter: Nicolas Duminil


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 ?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to