-->
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: Why hibernate lock table for reading when saving new item
PostPosted: Tue Dec 11, 2012 3:54 am 
Newbie

Joined: Wed Jan 30, 2008 9:27 am
Posts: 3
Hello,

I'm using hibernate 3.6 to control all the DB transactions with MSSQL 2008.

I have the following code:

Code:

Session session = sessionFactory.getCurrentSession();
session.setFlushMode(FlushMode.MANUAL);

Transaction tx = session.beginTransaction();

User u = new User();

session.save(u);

Thread.sleep(10000);

session.flush()
tx.commit();



While the thread is sleeping I can't read the current data from the table users (with the mssql studio management), why? (I understand if hibernate lock the table for inserting, but why for reading and updating).

Thank you.

* Edit: My bad, it's only lock the new record. If I use select top x * from table the data returns


Top
 Profile  
 
 Post subject: Re: Why hibernate lock table for reading when saving new item
PostPosted: Tue Dec 11, 2012 8:41 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
You need switch from Read Committed isoalation level to Snapshot Isolation Level,
see more info under:

http://www.databasejournal.com/features/mssql/snapshot-isolation-level-in-sql-server-what-why-and-how-part-1.html


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.