This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Knowing about the transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Knowing about the transaction" Watch "Knowing about the transaction" New topic
Author

Knowing about the transaction

krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,
I have a small doubt regarding the transaction.
Following is the code:

Lets say I am calling a method from a method which involves with the transaction.
Now, Can I know by any chance that I am with in a transaction from the method calculateUserCount()??
If the calculateUserCount() is another Bean method what would be the case?


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
E Lievaart
Greenhorn

Joined: Jul 06, 2008
Posts: 28
Actually, you can be sure that there is a transaction.
No transaction attribute is specified on the class or on the calculateUserCount().
The default transaction attribute is REQUIRED.
In other words there will always be a transaction when the method is called.

Usually you would use transaction attributes to answer the question you asked.
It makes little sense to use an attribute of SUPPORTS
and then poll the transaction, because you actually need one.
I you want to ensure that the method is always called within an existing transaction, then assign an attribute of MANDATORY.

Since the bean is stateful you can use the SessionSynchronization interface as well.
This way you can monitor the transaction status.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Knowing about the transaction
 
Similar Threads
persistence.xml file for MS SQL Server 2000
find and getReference methods
Exception while deleting a Entity
when to use catch block and when to use throws
doubt at respect TransactionRequiredException