-
1. Re: About “WFLYJPA0060: Transaction is required”
zhurlik Oct 25, 2019 7:15 AM (in response to usharik)1 of 1 people found this helpfulHi,
Maybe it can help you, I guess you are tying to use RESOURCE_LOCAL
Tackling RESOURCE_LOCAL Vs. JTA Under Java EE Umbrella and Payara Server - DZone Java
Thanks,
Vlad
-
2. Re: About “WFLYJPA0060: Transaction is required”
usharik Oct 25, 2019 7:42 AM (in response to zhurlik)Hi,
Very likely that is what I need! Thank you!
-
3. Re: About “WFLYJPA0060: Transaction is required”
smarlow Nov 5, 2019 3:22 PM (in response to zhurlik)I hadn't seen that doc before, looks well written!
-
4. Re: About “WFLYJPA0060: Transaction is required”
smarlow Nov 5, 2019 3:39 PM (in response to usharik)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&characterEncoding=UTF-8&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>What should I do to fix?
I think that you should make two changes, switch to RESOURCE_LOCAL and also do not use a "transaction scoped persistence context" (use @PersistenceUnit EntityManagerFactory yourEMF instead of @PersistenceContext EntityManager yourEM).
Why it works this way?
When you inject an @PersistenceContext into an EntityManager, the underlying entity manager (persistence context) that is managed by the JPA container, will ensure that any non-JTA-transactional calls to EntityManager.remove/merge/persist/refresh methods, will throw a "Transaction Is Required" exception.
Scott