You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Richard Grin <Ri...@univ-cotedazur.fr> on 2019/07/25 11:33:23 UTC
Insert Code an EntityManager in an EJB uses a UserTransaction even if
CMT
Hi,
I think there is an error in the code generated by NetBeans to use an EntityManager.
I create a session Beans stateless.
In this session bean, Alt-Insert > Use Entity Manager...
The inserted code use UserTransaction when the bean is not annotated with
@TransactionManagement( TransactionManagementType.BEAN):
@PersistenceContext(unitName = "samplePU")
private EntityManager em;
@Resource
private javax.transaction.UserTransaction utx;
public void persist(Object object) {
try {
utx.begin();
em.persist(object);
utx.commit();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
throw new RuntimeException(e);
}
}
Normally the transaction should be managed by the container without using UserTransaction.
Richard