-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Please: programatically setting each transaction isolation l
PostPosted: Sun Dec 09, 2007 6:19 pm 
Newbie

Joined: Thu May 26, 2005 7:25 am
Posts: 13
Hibernate version: 3.2

Hello,

please, could you tell me how can I set individual transaction isolation level? I just cannot find the api call, only the general config property.

I also wanted to know if it's possible to change the level to a more strict one in the middle of a transaction. Thanks.

jv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 12:50 pm 
Newbie

Joined: Mon Oct 29, 2007 2:33 pm
Posts: 16
Location: Cambridge, MA
Even at the JDBC level, you can only specify the isolation level at the start of a transaction, before the first db access. The database needs to know what locking is needed for the very first read access. At the JDBC level, you can use the API

Connection.setTransactionIsolation(int level), where level = TRANSACTION_SERIALIZABLE, etc.

If you are running in an application server, you are using Connections owned by it, and should not try to manipulate the isolation level at runtime. You can add pessimistic locking as needed to your base level, or run at serializable and make multiple small transactions to lessen contention, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 5:43 pm 
Newbie

Joined: Thu May 26, 2005 7:25 am
Posts: 13
Thanks a lot for your kindly answer. I'm no way a DBA but I infer you're telling me it's not a good practice to decide what kind of isolation is more suitable for each transaction no matter it's nature. It doesn't look very intuitive but explains why there isn't any easy way to do it.

Thanks again.

jv


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 5:58 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
ciberado wrote:
Thanks a lot for your kindly answer. I'm no way a DBA but I infer you're telling me it's not a good practice to decide what kind of isolation is more suitable for each transaction no matter it's nature. It doesn't look very intuitive but explains why there isn't any easy way to do it.

Thanks again.

jv


why do you need to set it anyways?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 12, 2007 12:46 pm 
Newbie

Joined: Mon Oct 29, 2007 2:33 pm
Posts: 16
Location: Cambridge, MA
Actually, at the database level it is OK to have different transactions run at different isolation levels. It's only because of the Connection pooling of the application server that makes us stick to one level. If you are using a Connection directly from the JDBC driver you can use multiple levels.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 5:58 am 
Newbie

Joined: Thu May 26, 2005 7:25 am
Posts: 13
Thanks eoneil & farzad.

I would find interesting to be able to specify the lesser resource intensive isolation level as a default but some times you need a serialized isolation (coded as 8, if I remember it right).

And I would like to continue using hibernate in those cases, without needing to work at connection level.

Any suggestion appreciated ;-)

jv


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 11:47 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
ciberado wrote:
Thanks eoneil & farzad.

I would find interesting to be able to specify the lesser resource intensive isolation level as a default but some times you need a serialized isolation (coded as 8, if I remember it right).

And I would like to continue using hibernate in those cases, without needing to work at connection level.

Any suggestion appreciated ;-)

jv


Is it possible for you to define two data sources each of which has the specific isolation level you want? Then you could use two session factories for each isolation level. However, you will definitely need to use distributed transactions if these two scenarios can be used together.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 4:11 pm 
Newbie

Joined: Mon Oct 29, 2007 2:33 pm
Posts: 16
Location: Cambridge, MA
If you're trying to get good performance, it's good to avoid distributed transactions if possible.

The bad performance from serializable isolation, if any, comes about from long-held locks (rather than the overhead of *creating* the locks, which is almost always negligable). So if you run at serializable, and add more commits to your less-critical code, you should be able to get good performance and still have serializable where you need it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.