Transaction problem

Discussion in 'Java' started by gk, Nov 11, 2006.

  1. gk

    gk Guest

    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 ?
     
    gk, Nov 11, 2006
    #1
    1. Advertising

  2. gk wrote:
    > 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
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Nov 11, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eitan

    Error in OLEDB Transaction

    Eitan, Apr 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,005
    Tad Marshall
    Apr 10, 2005
  2. Eitan

    long time transaction

    Eitan, Apr 11, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    603
    Eitan
    Apr 11, 2005
  3. mike
    Replies:
    0
    Views:
    375
  4. Vencz Istv?n
    Replies:
    2
    Views:
    308
  5. CJM
    Replies:
    0
    Views:
    132
Loading...

Share This Page