-->
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.  [ 2 posts ] 
Author Message
 Post subject: Session cache have very nasty impact on some select
PostPosted: Wed May 19, 2010 2:39 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
Looking
viewtopic.php?p=2383408
to solve one of my current problems with hibernate not behaving properly I think I found
a very nasty flow in the way hibernate session is caching retrieved information under some
special circumstances

Lets assume I have the following statements in my code which (supposedly) allow me to
implement a certain form of row locking for DB like MySQL MyISAM storage engine which do not have
this functionality by default

String lockStr = "SELECT GET_LOCK('" + c + "_" + id + "',5)";
SQLQuery qq = sqlQuery(lockStr);
List<Object[]> res = qq.list();

wouldn't the session cache give me twice the same result (1 in this case) in 2 threads meaning they both got the lock
whereas the 1st thread should clearly get 1 and the second 0 ???


Top
 Profile  
 
 Post subject: Re: Session cache have very nasty impact on some select
PostPosted: Wed May 19, 2010 3:26 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
1. The type of query you are executing is not cached in the session cache. It can be cached in the second-level cache but this is configurable per-query level by calling Query.setCacheable().
2. A session is not thread-safe so if you have two threads you should have two sessions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.