aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Trasactions in EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Trasactions in EJB" Watch "Trasactions in EJB" New topic
Author

Trasactions in EJB

SriLatha Vuyuru
Greenhorn

Joined: Oct 19, 2004
Posts: 1
Hi,

I have an issue in my service.
I am using EJB2.0 and using WSAD 5.1.2 for coding and testing.
My handler class calls the method A in the Session Bean.
I can pass n number of actions in a single request which should go in a single transaction. In case of failure of any action all should be rolled back.
1. I have a method A being called form the client.
2. The method A inturn calls method B.
3. Method B performs Add or update or delete on a particular table in a database.
4. Before Adding or updating or deleting the data Method B needs to check whether the data send is valid or not.
5. So it calls Method C which checks for the data.
6. Method C has all the select statements and checks whether the data in the request is valid or not.
7. Method C while doing the checks connects to two different databases. And returns the data back to Method B.
8. Method B then checks for the flag send by method C and if the flag is true it has to roll back the previous transactions.
9. Else it will add or update or delete the data for that action

Now the problem is my request contains multiple actions. One single request can have multiple adds, multiple updates and multiple deletes.

If for example we have 3 adds 2 updates and 2 deletes

The first 3 adds are done successfully and 1 update done successfully and the second update fails then it has to roll back first 4 successful adds and updates to the database. Here I am facing an IllegalState Exception problem.

What should be the transaction attributes set to each method A, B and C

If I set A as not supported and B required and C Not supported then the connection to 2 different databases is working fine but in case of failure it cribs saying the same exception.

If I make A to Required and B to Required and C to NotSupported then it cribs with the same exception while connecting to 2 different databases.

Note: Method C should be NotSupported and The transaction type is Container Managed.

Can any one give me a solution to this problem.
Mark a reply to vs_latha@ureach.com
Regards,
Latha
Bruno Collet
Ranch Hand

Joined: Jun 08, 2004
Posts: 40
I am not sure that I understand the problem completely, but I would set method A to RequiresNew and all others to Required so that the whole request is executed in a single transaction. The fact that method C must be NotSupported is not a problem since it does not change the data.
However, if your transaction managers for the two databases are separated (for example if they are accessed from different WAS instances), you must make sure that your system supports two-phase


Bruno Collet<br /><a href="http://www.practicalsoftwarearchitect.com" target="_blank" rel="nofollow">www.practicalsoftwarearchitect.com</a><br />- The Paradox of Software Architecture: It is easy to make a complex architecture, but it is difficult to make a simple architecture.
Bruno Collet
Ranch Hand

Joined: Jun 08, 2004
Posts: 40
I am not sure that I understand the problem completely, but I would set method A to RequiresNew and all others to Required so that the whole request is executed in a single transaction. The fact that method C must be NotSupported is not a problem since it does not change the data.
However, if your transaction managers for the two databases are separated (for example if they are accessed from different WAS instances), you must make sure that your system supports two-phase commit.
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
Assuming you are calling MethodB and MethodC directly from MethodA, then it doesn't matter what the transaction attributes of MethodB and MethodC are because they will not be used. Only calls to MethodB and MethodC that go through the Remote/Local Interface will have the transactional semantics applied.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trasactions in EJB