• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session bean tranasactions with CMP  RSS feed

 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using session beans in my app, from a session bean I'll call multiple entity beans(CMP) in a transaction. Can any one tell me the best approach to use multiple entity beans(CMP)in a transaction.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can start the transaction in the session bean and have tx attribute of required in entity bean. I am not sure whether this is of much use to you.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I for one am missing something here. What do you mean by "approach" with regard to the operations being performed within a transactional context? How to lookup beans? How to set transaction attributes? Something else?
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My transaction requires updating the contents of three different CMP entity beans. The update should be performed on all three beans or none.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Just define your transaction attributes (for the session bean as well the entity beans) to "Required". Then, if the session bean is invoked without a transactional context, it will acquire a new one, and if any of the entity beans fail, the whole transaction will be rolled back.
Another question is whether you should use "Required" or "RequiresNew" for the session bean (i.e. whether you want to rollback the caller's transaction or not).
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx!
Can I use UserTransaction for the same purpose? By using context.getUserTransaction(), I can get UserTransaction and then commit or rollback.Is this a good approach?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use UserTransaction for the same purpose? By using context.getUserTransaction(), I can get UserTransaction and then commit or rollback.Is this a good approach?

In the Session bean?
Yes you can .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!