-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session.lock generates update statement
PostPosted: Mon Dec 24, 2007 11:12 pm 
Newbie

Joined: Fri Mar 11, 2005 5:36 pm
Posts: 10
Hi,

I was trying to initialize the association by using HibernateCallBack for detached objects. However, I was seeing some update statements being fired even though I was just trying to reattach (lock) the object back to the current hibernate session within the HibernateTemplate. It looks like this was also related to the fact that the table has the version column inside. Am I missing something?

Hibernate version:3.2.4 sp1

Mapping documents:

Code between sessionFactory.openSession() and session.close():
final Object parent = theParent;
final Object child = theChild;
hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
session.lock(parent, LockMode.NONE);
Hibernate.initialize(child);
return null;
}});


Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Hibernate: update TABLE_A set version=?, CREATED_BY=? ... where ID=? and version=?



Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: flushing updates occurs often
PostPosted: Fri Dec 28, 2007 6:10 pm 
Newbie

Joined: Tue Mar 08, 2005 12:24 pm
Posts: 9
Location: Boston
Hibernate decides when to flush updates - I assume these are updates that have been made programmatically but have not yet been sent to the DB?

Not sure why the lock() call would do this, but it may be that Hibernate needs to flush all updates so that when it queries the version number to avoid optimistic lock failure it gets the up-to-date version number rather than the version number from before you started making changes.

I usually just accept that the flushing of changes to the DB will be unpredictable.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 6:18 pm 
Newbie

Joined: Fri Mar 11, 2005 5:36 pm
Posts: 10
No, there's no update for the object. I was just trying to re-attach the object to the current session and initialize the associated collection.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 6:36 pm 
Newbie

Joined: Fri Jan 11, 2008 6:32 pm
Posts: 2
I am seeing the same problem. Session.lock seems to be causing a update to be generated. I have a break point in my code and saveOrUpdate is never being called.


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