-->
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: BatchUpdateException when calling HibernateTemplate.update()
PostPosted: Thu Mar 13, 2008 10:13 pm 
Newbie

Joined: Thu Mar 13, 2008 10:10 pm
Posts: 1
Hello,

In my dao layer, I have two methods which load and update records in a user table. The user table is mapped one to one, and lazy loading is set to false. In these methods, I am using Spring's HibernateTemplate.


public User loadUserByUsername( String username )
{
List results = getHibernateTemplate().find("from User user where user.username= ?", username);
return (User) DataAccessUtils.uniqueResult( results );
}

public void updateUser( User user)
{
getHibernateTemplate().update(user);
}



I am calling both these methods from a service layer to retrieve a user by username, modify it, then update the record. Basically, something like this:



User user = getUserDao().loadUserByUsername(username);
user.setEmail("test@test.com");
getUserDao().updateUser(user);





First I did not execute these methods inside a transaction, and I saw the following stack trace:

11 Mar 2008 12:42:29,171 [http-8050-Processor25, ] ERROR org.hibernate.event.def.AbstractFlushingEventListe ner - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

...

Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.ServerPreparedStatement.executeBatc h(ServerPreparedStatement.java:647)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:195)

Once I put these calls inside a transaction, it works fine. What I would like to know is why I need the transaction for this update to work? I am using mysql 5

Thanks.


Top
 Profile  
 
 Post subject: Re: BatchUpdateException when calling HibernateTemplate.update()
PostPosted: Tue Mar 01, 2011 8:02 pm 
Newbie

Joined: Thu Jan 07, 2010 4:31 pm
Posts: 2
Did you figure this one out? I'm having a similar problem.


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.