[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Distributed Transactions Exception in J2EE

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
kirtan_a
Asked:
kirtan_a
1 Solution
 
petmagdyCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now