• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to Rollback Transaction in EJB2.0?

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am developing small EJB CMP2.0 application. Now I have two tables in my database with one-to-one relation. I have Mapped one-to-one relatonship between my EJB's corresponding to those tables using EJB CMR. My contants of ejb-jar.xml & jbosscmp-jdbc.xml for same are as follows:-

ejb-jar.xml
=============================
<relationships >
<ejb-relation >
<ejb-relation-name>empmaster-to-usrmaster</ejb-relation-name>
<ejb-relationship-role> <ejb-relationship-role-name>empmaster-has-one-usrmaster</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<cascade-delete/>
<relationship-role-source >
<ejb-name>EmployeeMaster</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>userMaster</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>usrmaster-has-one-empmaster</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<cascade-delete/>
<relationship-role-source >
<ejb-name>UserMaster</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>employee</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
=============================

jbosscmp-jdbc.xml
=============================
<relationships>
<ejb-relation>
<ejb-relation-name>empmaster-to-usrmaster</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>empmaster-has-one-usrmaster</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>employeebeanid</field-name>
<column-name>userid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>usrmaster-has-one-empmaster</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>userbeanid</field-name>
<column-name>employeeid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
</relationships>
=============================

All the things working fine.
Now Problem is that how to perform rollback if some problem will occur in inserting record in second bean after record is inserted in first bean. Currently I am using session bean for calling 'create' method on both the beans in realationship. So how to perform rollback in case of failure??

Please tell me.

Thanx
Prash
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your session bean, start a transaction (container managed is usually best) for the method which calls your entity beans. This transaction must be propagated into the entity beans, so these entity bean methods must have a trans attribute such as Required. If there is a failure which causes a RuntimeException to be thrown in either entity bean, the container will automatically rollback the transaction before the session bean method ends.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic