If I inject the UserTransaction via @Inject nothing happens. Printing out the transaction gives Transaction: unknown
If I inject the UserTransaction via @Resource I get NameNotFoundException with message be.sample.WidgetCreator not bound
.
Should deploy as an ear probably, or try glassfish.
This should work :
@Inject @MyDB private EntityManager db; @Resource private UserTransaction ut; ... ut.begin(); db.joinTransaction(); db.persist(myEntity); db.flush(); ut.commit();
Not sure that flush is mandatory.
Sorry @Resource should be :
@Resource(mappedName="java:comp/UserTransaction") private UserTransaction ut;
Don't know why the mappedName is necessary, but it works in both JBoss 6 and GF 3.
According to the spec (3.6) @Inject UserTransaction should work. If it doesn't, that's a bug.
Right, this works perfectly (in JB6 at least) :
@Inject @MyDB private EntityManager db; @Inject private UserTransaction ut; ... ut.begin(); db.joinTransaction(); db.persist(myEntity); db.flush(); ut.commit();