Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB Transaction confusion

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Now I am confusing the EJB transaction. Too much contents there. Anybody can give me some concise rules when using the 6 transaction attributes in real world EJB programming? Usually in what situaction we should use which attribute ?
Thanks.
Thanks.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ask yourself some questions:
1) Whether the operation "must-have", "can-have", or "should-not-have" a transactional context?
This limits your choices to {Required, RequiresNew, Mandatory}, {Supported}, and {NotSupported, Never}, respectively.
From these sets, only the first one ("must-have") is left to resolve because, as a thumb rule, you should avoid using Never at all times.
2) If the operation fails, should *everything* rollback or just everything done within that particular operation?
If just the changes internal to the operation should rollback, use RequiresNew. If all changes should rollback, proceed to question 3.
3) Does it actually matter whether the transaction already exists?
If it does for some reason (can't really think of one), use Mandatory. If you don't care whether the transaction already exists or whether it's created just for this operation, use Required.
 
vinay Yalamanchili
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good description..thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic