[J2EE] JPA JTA

作者: luoqr (.....)   2015-08-03 22:59:44
persistence.xml
<persistence-unit name="..." transaction-type="JTA">
...
@Stateless
public class EjbService implements EjbServiceRemote {
@PersistenceContext EntityManager em ;
@Resource SessionContext ctx ;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void test(){
User u = new User(...) ;
em.persist(u);
em.flush();
ctx.setRollbackOnly();
}
}
誰能告訴我...為什麼多了 em.flush() 就不會 rollback....
作者: luoqr (.....)   2015-08-03 23:05:00
Jboss eap 6.3+hibernate
作者: kojilin (阿~~小達達)   2015-08-04 09:48:00
datasource 是不是設 auto-commit?
作者: swpoker (swpoker)   2015-08-04 14:53:00
Synchronize the persistence context to the underlyingdatabase->api說同步到資料庫
作者: luoqr (.....)   2015-08-04 21:17:00
自問自答.後來發現JBoss有個datasource enable JTA設定要開

Links booklink

Contact Us: admin [ a t ] ucptt.com