Solved

Distributed Transactions Exception in J2EE

Posted on 2004-10-29
254 Views
Last Modified: 2013-11-24
Hi all,
I'm facing a problem while developing some code in J2EE. I have a class which has two methods. One to insert a record in table ABC and another to update a record in table DEF. The transaction should be such that if there is an exception in either of the operations, the whole transaction should be rolled back. I'm calling the second method from the first one. While the first one is called from a session bean. When I use conn.commit() or conn.rollback(), it throws an exception saying commit or rollback cannot be called in distributed transactions.
also the whole transaction does not rollback. How can I properly handle such exceptions, and ensure that either both or none of the transactions occur?
Is it a problem of the driver used. I'm using Oracle as database, and Weblogic 8 as the app server.

can anybody help me out?
thanks in advance
kirtan
0
Question by:kirtan_a
    1 Comment
     
    LVL 13

    Accepted Solution

    by:
    kirtan,

    never use commit() or rollback() in EJB container, to do ur transaction:

    1- make sure that u r getting ur DB  connections from Datasource
    2- Use Declarative Transaction mangment, in ur ejb-jar.xml declare ur Session API as Transaction Type Required like this:

    <assembly-descriptor>
    ......

    <container-transaction>
          <method>
                <ejb-name>UrSessionBean</ejb-name>
                <method-intf>Remote or Local</method-intf>
                <method-name>urFuntionName</method-name>
                <method-params>
                      <method-param>param1</method-param>
                </method-params>
          </method>
          <trans-attribute>Required</trans-attribute>
    </container-transaction>

    .........

    </assembly-descriptor>


    by this way the Container will manage ur transaction and automatically if insertion into last table failed will roll back the transaction


    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Understanding @ResponseBody annotation 5 28
    Return ZipOutputStream using Servlet 2 18
    advance java 4 22
    parentbit challenge 3 14
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now