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:-
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??
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.