Getting Lock wait timeout exceeded; try restarting transaction

376 views
Skip to first unread message

Ragini

unread,
May 11, 2009, 11:41:35 AM5/11/09
to Java User Group For Pune city in India
Hi All,

I am giving detail information here :
Thanks in advance !

This is my hbm file :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.perennial.fambook.proxies.users">
<class name="UnRegisteredUsers" table="UNREGISTERED_USERS">
<id name="id" column="ID" type="integer">
<generator class="increment">
<!--param name="sequence">FAMBOOK_SETTING_PROFILE_SEQ</param-->
</generator>
</id>
<property name="firstname" column="FIRSTNAME" type="string"/>
<property name="lastname" column="LASTNAME" type="string"/>
<property name="gender" column="GENDER" type="integer"/>
<property name="dob" column="DOB" type="date"/>
<property name="email" column="EMAIL" type="string"/>
<property name="password" column="PASSWORD" type="string"/
>
</class>
</hibernate-mapping>

This is UnregisterUser java file:

package com.perennial.fambook.proxies.users;

import java.util.Date;

public class UnRegisteredUsers {
private int id;
private String firstname;
private String lastname;
private String email;
private Date dob;
private int gender;
private String password;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public int getGender() {
return gender;
}
public void setGender(int gender) {
this.gender = gender;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}


}


This is the table structure:

CREATE TABLE `unregistered_users` (
`ID` int(11) NOT NULL,
`FIRSTNAME` varchar(50) default NULL,
`LASTNAME` varchar(50) default NULL,
`GENDER` int(11) default NULL,
`DOB` date default NULL,
`EMAIL` varchar(50) NOT NULL,
`PASSWORD` varchar(50) default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `EMAIL` (`EMAIL`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



when I am saving unregisteredUsers object by

session.save(unregisteredUser);
session.flush();

Getting Exception:
BatchUpdateException : Lock wait timeout exceeded; try restarting
transaction.

Not getting the exact cause for this exception.
Some times it is working fine and sometimes throwing this exception

Please reply if anyone know about this.

Varun Deshpande

unread,
May 12, 2009, 5:10:29 AM5/12/09
to Java...@googlegroups.com, ragini.m...@gmail.com



2009/5/11 Ragini <ragini.m...@gmail.com>
hi,
Check that only your application is using that table. According to me some other application or process is using this table while  you are inserting data in the table. so you got exception. Your code is fine. no problem with you code. Another thing whether you got this exception for every single transaction or after many transaction you got this error. & which database you are using???  

--
Thanks
Varun Deshpande.
______________________________________________________________________
When You wish upon a star
Makes no different who you are
Anything your heart desire
will come true
______________________________________________________________________
Fulcrum Logic ( I ) Pvt. Ltd.
Phone : (+91) 20 30259300 Ext 393
email : varun_d...@fulcrumlogic.com

Ragini

unread,
May 12, 2009, 9:31:22 AM5/12/09
to Java User Group For Pune city in India
Hi varun,

Thanks for reply.

yes this table is accessed concurrently , as multiple users can do
registration at the same time.
For single transaction it is not giving me exception.
I am using MySQL 5.0 , JDK 1.6
Is there any solution ? please reply.


Thanks and Regards,
Ragini.


On May 12, 2:10 pm, Varun Deshpande <deshpande.va...@gmail.com> wrote:
> 2009/5/11 Ragini <ragini.marwad...@gmail.com>
> email : varun_deshpa...@fulcrumlogic.com<%20varun_deshpa...@fulcrumlogic.com>

Vaibhav

unread,
May 13, 2009, 6:49:57 AM5/13/09
to Java User Group For Pune city in India
Hi Ragini,

I have faced this problem earlier.
Have you made your method synchronized ?
There are two ways to fix this problem.

One is to make the code which saves,updates , deletes static
synchronized.
This will lock any thread trying to update data concurrently.

Other method is to use transaction for the save operation. You can
configure third party transaction tools in hibernate which can take
care of your problem.

Regards,
Vaibhav

Ragini

unread,
May 13, 2009, 9:42:41 AM5/13/09
to Java User Group For Pune city in India
Hi Vaibhav,

Thanks for Reply.
Reply all
Reply to author
Forward
0 new messages