jpa - CDI EntityManager fail -
hibernate says "an exception thrown hibernate means have rollback database transaction , close session immediately".
when persist method throws sqlexception , entitymanager becomes dirty, if close entitymanager, still in conversation scope.
i'm using: tomcat 7, cdi 1.1, hibernate 4.1;
is there way produce new entitymanager current conversation replace dirty?
@produces @conversationscoped public entitymanager create(entitymanagerfactory emf) { entitymanager em = emf.createentitymanager(); ...
viewbean
@named @conversationscoped public class myview implements serializable { enter code here @inject @getter private entitymanager em; ... public void persist(){ try{ getem().gettransaction().begin(); getem().persist(entityinstance); getem().gettransaction().commit(); }catch(exception e){ e.printstacktrace(); if(getem().gettransaction().isactive()){ getem().gettransaction().rollback(); } } }
no, there not. conversation scoped isn't scope entitymanager anyway. should request or default due transaction boundaries.
Comments
Post a Comment