• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Trasactions in EJB

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic