Hi All,
I want to use
Java CDI with transaction management but i am getting below exception
javax.persistence.TransactionRequiredException
Use case is
1. I have one DAO Impl class where i am injecting Entity manager
@PersistenceContext
protected EntityManager entityManager;
2. I have one service class annotated with @Named annotation.
Now in service class, i have one method, which i have tried to annoted with Transaction annotation
@Transactional(value=Transactional.TxType.REQUIRED)
public
String printMethod() {
List<ClientStatus> lst = clientStatusDao.getAll();
for (ClientStatus clientStatus : lst) {
System.out.println("----------------- clientStatus ------------ " + clientStatus.clientStatusDesc);
if(clientStatus.getClientStatus().equals("A")) {
System.out.println("----------------- changing client status ------------ ");
clientStatus.setClientStatusDesc("Activ");
clientStatusDao.updateStatus(clientStatus);
}
}
return s;
}
Here i am able to fetch the records from the database but on update i am getting below exception
javax.persistence.TransactionRequiredException
org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:116)
org.apache.openejb.persistence.JtaEntityManager.merge(JtaEntityManager.java:156)
I am not using
EJB. Some blogs i read that Java EE 7 along with JTA 1.2 does not require EJB for the transaction.
Not able to understand, where i am doing mistake.
Please help,
Regards,
Sunil