wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Questions for Kathy Sierra or Bert Bates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Questions for Kathy Sierra or Bert Bates" Watch "Questions for Kathy Sierra or Bert Bates" New topic
Author

Questions for Kathy Sierra or Bert Bates

Amy Caruso
Greenhorn

Joined: Feb 23, 2004
Posts: 14
What is the guideline of how BMT transaction isolation levels should be handled with session beans? And where may I find a piece of sample code doing that?
TIA for your help!
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Ah... this is a tough question because at Sun, the position is that isolation levels are *not* supposed to be something the bean developer should be involved in, and that this is purely a DBA issue. You *can* still set the isolation level at the "local resource level" (note to everyone here, nothing about isolation levels is on the exam , but it's not recommended. So, I'm going to wimp out and say that "the best practice for isolation levels is to leave it up to your database administrator". And it's a best practice for the bean developer personally, because I know I've worked with some DBA's who would pretty much threaten to kill you if you even *thought* about messing with isolation levels on the database. The attitude is, "Your job is to just do your updates, inserts, etc. and let US (meaning the DBAs) worry about the isolation levels."
But having said that... it does depend on two things:
1) the nature of your application (for example, is it truly critical that you never get an uncommitted read?)
2) the type of database that you're using, or more specifically--the type of locking mechanism that your database uses.
If you want maximum safety, you can just crank the dial on the isolation level all the way up to the "serializable" level. But that brings your concurrency down. So the general rule is that for performance you should always choose the LEAST restrictive isolation level that you can live with for your application, and consider the type of locking your particular database uses.
Still, though, you should try to avoid doing any of this from within your bean code! That will hurt the maintenance and reuse of your bean (if you set isolation levels on the resource in code, you would have to recode/recompile/retest your bean in order to make changes), and again, it's really a decision that should be pushed down to the database.
Most databases use one of the two middle levels of isolation as a default, and you can probably accept that unless you have some highly critical data where you need to strengthen the isolation (brining your concurrency down) or, the opposite, you have data where it really doesn't matter -- you just need a rough snapshot of what the database looks like at the time you do the read and it's not important if you get dirty reads, etc.
Hope that helps a little... sorry my answer is so wimpy , but I'm not a database admin and this isn't part of the EJB specification. (Although there used to be a way to set isolation levels on *CMT*, but that was in the first version of EJB and it caused all sorts of horrible problems so it was eliminated from the spec.)
My advice: leave it up to the database admin, but if you really need to do this yourself (like maybe you are supposed to wear BOTH the bean developer and database admin hat), then you'll have to consider the performance tradeoffs based on your specific business logic based on how your particular database does locking.
cheers,
Kathy
Amy Caruso
Greenhorn

Joined: Feb 23, 2004
Posts: 14
Thanks, Kathy. So, how is it handled in DD if we have to (as suggested on page 56 of Core J2EE Patterns by Deepak Alur et al, for example)? I am asking about the issue, because many industrial applications are still using session beans with BMT to handle the transaction isolation levels, even though they are using EJB 2.0. Hope you can help.
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions for Kathy Sierra or Bert Bates