-->
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.  [ 3 posts ] 
Author Message
 Post subject: session.save flush the data although FlushMode.COMMIT
PostPosted: Tue Dec 11, 2012 4:43 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.COMMIT);

Transaction tx = session.beginTransaction();

User u = new User();

session.save(u);

Thread.sleep(10000);

tx.commit();



Why does hibernate flush the new user before tx.commit()? I know this because when I do select * from table the table is lock until tx.commit().


Top
 Profile  
 
 Post subject: Re: session.save flush the data although FlushMode.COMMIT
PostPosted: Tue Dec 11, 2012 7:29 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
There are some situation where hibernate is forced to flush implicitly, i.e. when you do operations on EXTRA_LAZY collections.
In your case I guess it's because you are using native (AUTO) identifier-generation strategy for User entity,
where session.save(u) in order to obtain a definitive id for that user, is forced to do the insert immediately.
Aren't you using native (AUTO) identifier-generation strategy for User entity?


Top
 Profile  
 
 Post subject: Re: session.save flush the data although FlushMode.COMMIT
PostPosted: Tue Dec 11, 2012 8:16 am 
Newbie

Joined: Wed Jan 30, 2008 9:27 am
Posts: 3
Yeah you are right.

The solution that we implemented here is to setup the isolation level to 1 (TRANSACTION_READ_UNCOMMITTED) by declaring in the hibernate.cfg.xml file:

<property name="hibernate.connection.isolation">1</property>

I may use the MSSQL "READ_COMMITTED_SNAPSHOT" isolation level, I need to read more about it.

Thank you very much


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