UserTransaction
Hi, I'm working in an EJB with transactions handled by the bean, I use
the UserTransaction object to start and finish each transaction, the
EJB has some code like this:
/* ************************* */
ut.begin();
try {
/* An insert or update query */
ut.commit()
} catch (Exception e) {
ut.rollback();
}
.. . .
/* OtherClass was made by somebody else, I only have the jar file not
the source code */
OtherClass otherClass = new OtherClass();
otherClass.setTransaction(ut);
otherClass.doStuff();
.. . .
ut.begin();
try {
/* An insert or update query */
ut.commit()
} catch (Exception e) {
ut.rollback();
}
/* ************************* */
This code can produce errors when the code in the class "OtherClass",
begins a transaction and doesn't execute ut.commit() or ut.rollback().
I know that there is a method called ut.getStatus() that returns the
state of the thread's transaction, my question is, which is the best
way to check the transaction status and execute well ut.commit() or
ut.rollback() ?
Thanks,
Andrés
.
Relevant Pages
- Re: J2EE - entities - When do JPA entity units get saved into the database
... as JPA entities and EJB 2 Entity Beans have ... serialized as-is and returned across remote calls. ... field changes back to the database if the changes occur within the ... same transaction that the entity was loaded in AND if the object has ... (comp.lang.java.programmer) - Re: EJB container manager transaction
... > If something goes wrong I would like to abort transaction. ... > At moment I can see, this is done from container only when the EJB method ... > Can I do it in one of class used by EJB without relying on Exception ... you call setRollbackOnly you should such code precede by test with ... (comp.lang.java.programmer) - Re: Regarding EJBs
... Assume that I have an EJB with two functions fn1 and fn2. ... Please note that only fn1 is exposed to outside world, ... The reason for calling it via its remote interface may be to allow CMT transaction demarcation if the method is transactional. ... (comp.lang.java.programmer) - Re: EJB - Why do we need java persistence on top of a database?
... ANSI-SQL is database independent as well, ... overhead of EJB. ... Isn't a transaction an application level issue? ... And with JDBC you can just do rollback(). ... (comp.lang.java.programmer) - UserTransaction
... Hi, I'm working in an EJB with transactions handled by the bean, I use ... OtherClass otherClass = new OtherClass; ... begins a transaction and doesn't execute ut.commitor ut.rollback. ... (comp.lang.java.programmer) |
|