You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Ricardo <ri...@intervisit.com> on 2013/02/11 21:58:21 UTC
handling new transaction inside transaction does not work
Hi, I have an "outer" method that calls an "inner" method. Both use the same
DAO class. I have annotated the inner method with *REQUIRES_NEW*. The inner
method throws an exception to the outer method, e.g. if some unique key
conflict happens inside the inner method.
I expect the inner method to get his own transaction, so the exception there
should not be of any influence on the outer method. The outer method catches
the exception from the inner method, so the outer method is not interrupted,
and continues after the call to inner.
However, my database log shows that only one db transaction is being used,
meaning that inner works in the same as outer. When inner throws an
exception, the effects of outer are rolled back, and that should not happen
imho.
Why is there not a second transaction created for inner? Anyone got the
same problem, and solved it?
--
View this message in context: http://openejb.979440.n4.nabble.com/handling-new-transaction-inside-transaction-does-not-work-tp4660716.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: handling new transaction inside transaction does not work
Posted by Ricardo <ri...@intervisit.com>.
Thx, I will study a bit harder, and maybe ask more later on :-)
--
View this message in context: http://openejb.979440.n4.nabble.com/handling-new-transaction-inside-transaction-does-not-work-tp4660716p4660736.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: handling new transaction inside transaction does not work
Posted by Romain Manni-Bucau <rm...@gmail.com>.
AutheticationService is not an ejb so whatever the @transactionXxx you use
it will be ignored
Le 12 févr. 2013 08:46, "Ricardo" <ri...@intervisit.com> a écrit :
> // class is not annotated
> public class AuthenticationService {
>
> @Inject
> private UserDAO userDAO;
>
> @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
> private void inner() throws Exception {
>
> User user = userDAO.findByName("scott");
> user.setUserName("rick");
>
> userDAO.update(user); // will fire EntityExistException because
> there
> is already record with that name
> }
>
> public AuthenticationServiceObject outer() {
>
> User user = userDAO.findByName("tiger");
> gebruikerDAO.update(gebruiker);
>
> try {
> inner();
> } catch (Exception e) {
> System.out.println("INNER FAILS: " + e.getMessage());
> }
> return new AuthenticationServiceObject(0, "blahblah");
> }
> }
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/handling-new-transaction-inside-transaction-does-not-work-tp4660716p4660719.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: handling new transaction inside transaction does not work
Posted by Ricardo <ri...@intervisit.com>.
// class is not annotated
public class AuthenticationService {
@Inject
private UserDAO userDAO;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void inner() throws Exception {
User user = userDAO.findByName("scott");
user.setUserName("rick");
userDAO.update(user); // will fire EntityExistException because there
is already record with that name
}
public AuthenticationServiceObject outer() {
User user = userDAO.findByName("tiger");
gebruikerDAO.update(gebruiker);
try {
inner();
} catch (Exception e) {
System.out.println("INNER FAILS: " + e.getMessage());
}
return new AuthenticationServiceObject(0, "blahblah");
}
}
--
View this message in context: http://openejb.979440.n4.nabble.com/handling-new-transaction-inside-transaction-does-not-work-tp4660716p4660719.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: handling new transaction inside transaction does not work
Posted by Romain Manni-Bucau <rm...@gmail.com>.
hi
can you reproduce it in a sample?
*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*
2013/2/11 Ricardo <ri...@intervisit.com>
> Hi, I have an "outer" method that calls an "inner" method. Both use the
> same
> DAO class. I have annotated the inner method with *REQUIRES_NEW*. The inner
> method throws an exception to the outer method, e.g. if some unique key
> conflict happens inside the inner method.
>
> I expect the inner method to get his own transaction, so the exception
> there
> should not be of any influence on the outer method. The outer method
> catches
> the exception from the inner method, so the outer method is not
> interrupted,
> and continues after the call to inner.
>
> However, my database log shows that only one db transaction is being used,
> meaning that inner works in the same as outer. When inner throws an
> exception, the effects of outer are rolled back, and that should not happen
> imho.
>
> Why is there not a second transaction created for inner? Anyone got the
> same problem, and solved it?
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/handling-new-transaction-inside-transaction-does-not-work-tp4660716.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>