• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Distributed transaction , connnection.commit

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use WL 8.1 on Win 2000.

I am getting the following error:

Cannot call Connection.commit in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed.

Following is the code :

ctx = new InitialContext();
String datasource = (String)ctx.lookup("java:comp/env/dataSourceName");
ds = (DataSource)ctx.lookup(datasource);

Can anybody enlighten me what's going on here ? Am I using distributed transaction ? I think I am not....then why am I getting this errors for Connection.commit ?

Thanks in advance
-Anand.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anand,


Cannot call Connection.commit in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed.


These calls are forbidden if you use CMT:
  • The commit, setAutoCommit, and rollback methods of java.sql.Connection
  • The getUserTransaction method of javax.ejb.EJBContext
  • Any method of javax.transaction.UserTransaction


  • Please check if you�re calling commit.
    Regards.
     
    Anand Gondhiya
    Ranch Hand
    Posts: 155
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    what is CMT? Do you mean to say Container managed transaction ?

    just to give info , I don't use Container-Managed-Persistence.
     
    Anand Gondhiya
    Ranch Hand
    Posts: 155
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And yes...I am calling con.commit();
     
    Valentin Tanase
    Ranch Hand
    Posts: 704
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You're right, I mean container managed transaction.
    Well, that's the problem though. In CMT the EJB container sets the boundaries of the transactions and your code is not allowed to interfere with these boundaries. Therefore the error you get is very legitimate. Hence you either get rid of those commits, or use bean managed transaction.
    And by the way, why do you need to manually commit the transaction? Aren�t the standard J2EE transaction attributes good enough for your app?
    Regards.
     
    Anand Gondhiya
    Ranch Hand
    Posts: 155
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks a lot Valentin..

    And by the way, why do you need to manually commit the transaction? Aren’t the standard J2EE transaction attributes good enough for your app?



    I am working on maintainance project so not allowed to use my intelligence much !!! So I am directing all my energy for bypassing these problems ....

    Just to give you more info..... The code sets con.setAutoCommit(false); and then issues con.commit();

    Any more ideas ? Thanks again...

    -Anand.
     
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This could be because the database drivers that you are using are ditributed transaction(XA) enabled.
    Check the database drivers in your Weblogic console. You may need to change your datasource to point to a connection pool that does not use XA drivers.

    Hope that helps.
     
    Valentin Tanase
    Ranch Hand
    Posts: 704
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    Any more ideas ? Thanks again...


    There are two ways to implement transactions: either use JDBC transactions (which you�re doing), or to use the JTA/JTS transactions. The second one could be implemented getting the UserTransaction from the ejb context:

    One big difference between these two models is that only the second one supports global transactions.
    Some containers might have special setting for data sources in order to honor global transactions (the container will always create a Tx DataSource, although the underlying connection pool is using a non-XA JDBC driver). This and the fact that you�re using JDBC transactions might be a reason for your failures.
    Regards.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic