Transaction problem

G

gk

QUESTION 1:



can we use JTA API in a web container ?

say , i have a servlet where i am doing transaction to 3 different DB
as a unit.

can we apply transaction here ?

how the transaction will be activated ? does web container has any
transaction manager in built ?


In application server , we use this way ,

UserTransaction tranContext = (UserTransaction)
initContext.lookup("java:comp/UserTransaction"); // this is offered by
app server .
tranContext.begin();
// get and manipulate data sources or EJB's
tranContext.commit();


How do i get the transactin Context from an web container ? i want to
run my jsp+servlet in Tomcat

is it possible ?


QUESTION 2:

"..............................................
JTA isn't perfect. In fact, compared to the type of control we'll see
next with container-managed transactions (CMTs) in EJBs, JTA is a blunt
instrument:

If you are using JTA there is no individual control over data sources
and other resources. If you obtain a connection from a data source
within a transaction, that connection will be enlisted within the
transaction. You can't make it not enlisted or force it to commit
otherwise.

You can't suspend a JTA transaction; once the transaction is started it
must be either committed or rolled back. If you try to start another
JTA transaction on the same thread as an existing one, it will cause an
error.
..........................
.........................."




does JTA has become obsolete ?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

gk said:
can we use JTA API in a web container ?

say , i have a servlet where i am doing transaction to 3 different DB
as a unit.

can we apply transaction here ?

how the transaction will be activated ? does web container has any
transaction manager in built ?

In application server , we use this way ,

UserTransaction tranContext = (UserTransaction)
initContext.lookup("java:comp/UserTransaction"); // this is offered by
app server .
tranContext.begin();
// get and manipulate data sources or EJB's
tranContext.commit();
>
> How do i get the transactin Context from an web container ? i want to
> run my jsp+servlet in Tomcat
>
> is it possible ?

You can do the same in a servlet container, if you have
a transaction manager.

For Tomcat see:

http://www.onjava.com/pub/a/onjava/2003/07/30/jotm_transactions.html?page=1
http://static.raibledesigns.com/downloads/howto-tomcat-jotm.html
JTA isn't perfect. In fact, compared to the type of control we'll see
next with container-managed transactions (CMTs) in EJBs, JTA is a blunt
instrument:

If you are using JTA there is no individual control over data sources
and other resources. If you obtain a connection from a data source
within a transaction, that connection will be enlisted within the
transaction. You can't make it not enlisted or force it to commit
otherwise.

You can't suspend a JTA transaction; once the transaction is started it
must be either committed or rolled back. If you try to start another
JTA transaction on the same thread as an existing one, it will cause an
error.

I belive it is implementation specific whether JTA support nested
transactions or not.
does JTA has become obsolete ?

No.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top