• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deafult behaviour of EJB Container Managed Transaction  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is regarding EJB Container Managed Transactions .

By Default, transaction attribute for a method of a bean in the container-managed transaction demarcation is the REQUIRED attribute and the transaction attribute does not need to be explicitly specified.

As It says that the default is Required .

Will this is not a drawback ??

I am having a method inside my session Bean for getting Data say for example :



As this is only a select Operation . I dont want my method to run under a Transaction , will this run under a Required Transaction ??
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure there is that much of a draw-back if your method starts/commits a transaction. However, if you don't care whether or not your method is run under a transaction, then use SUPPORTS for the TransactionAttribute. This way, if there is a transaction already running, your method will join it. If there isn't a transaction already running, your method won't bother starting one.

If you don't want your method called under a transaction, then you can use NOT_SUPPORTED. If a transaction is in play, it will be suspended and your method will be called without a transaction.

Hope this helps,
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want your method called under a transaction, then you can use NOT_SUPPORTED.


Thanks good idea , but is there anything like TRANSACTION_NONE (While googling this i found this wrt to JDBC Only ) .
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand what you're trying to accomplish. Perhaps if you explain what you want to have happen in the following two cases:

1. Your bean method is called while the container/caller has a transaction in progress, and;

2. Your bean method is called while the container/caller has no transaction in progress.

Do you think that if you execute your search while running within the context of an existing transaction, it will be slower somehow?

By the way, if you don't already have it, pick up the book EJB3 in Action, by Manning publications. It's an excellent training/reference book for EJB3! I've found it invaluable in my road to understanding EJB3.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!