jpa - No active transaction in EJB @Schedule method -
i have ejb @schedule marked method, persists entity database. within method, when i'm calling entitymanager.flush() after persist(), i'm getting javax.persistence.transactionrequiredexception: no transaction active
afaik ejb methods transactional, i'm getting error if additionally mark method @transactionattribute(required).
when manage transaction manually entitytransaction.begin() , commit(), works ok.
i'm using wildfly 10.0 final on jdk 8u74, eclipselink 2.6.0.
here persistence.xml:
<?xml version="1.0" encoding="utf-8"?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1"> <persistence-unit name="mainpu" transaction-type="jta"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <jta-data-source>java:/datasources/exampleds</jta-data-source> <class>com.example.myentity</class> </persistence-unit> </persistence> myejb.java:
package com.example; import javax.ejb.*; import javax.ejb.timer; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; @startup @dependson("apputils") @singleton public class myejb { @persistencecontext(unitname = "mainpu") private entitymanager em; @schedule(hour = "*", minute = "*", second = "*/20", info = "", persistent = false) private void dostuff(timer timer) { myentity entity = new myentity("test" + math.random(), "test value"); em.merge(entity); em.flush(); } }
when use jta commit , flush changes database , close current transaction. so, when em.flush(), transaction closed.
Comments
Post a Comment