-->
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: Hibernate - JDBC Lock wait timeout exceeded Error!
PostPosted: Fri Jan 04, 2008 6:55 pm 
Regular
Regular

Joined: Thu May 04, 2006 5:24 am
Posts: 55
Hi,

I have one simple class named Receiver, which I have annotated with JPA annotations, and
I have table with the same name in the database. Now, I'm trying to use JUnit 4 to test is
persisting with Hibernate EntityManager is working properly, but I got an error (below).
When I restart Windows and run this test it works, but the second time when I run it I got
this error (below). What is the problem ?! I don't know how to solve this (simple?) situation :-(.

Thank you in advance.

--
Test class is:


Code:
public class ReceiverServiceHibernateImplTest {

private EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("punit");
private EntityManager em =  emFactory.createEntityManager();

   
   @Test
   public void testFindAll() {
      em.getTransaction().begin();

      Receiver rec1 = new Receiver();
      rec1.setName("John");
      rec1.setId(1L);

      em.persist(rec1);

      em.getTransaction().commit();  <- IN THIS LINE I HAVE AN EXCEPTION!!! TIMEOUT EXCEEDED

      List<Receiver> receivers = em.createQuery("from Receiver").getResultList();
      assertEquals(1, receivers.size());

      em.close();
      emFactory.close();
   }
}


--
My configuration:

Eclipse Europa 3.3 + jdk 1.5.0_12
JUnit 4
Hibernate 3.2.5 GA
Hibernate Annotations 3.3.0 GA
Hibernate EntityManager 3.3.1 GA
MySQL 5.0.45 + mysql-connector-java-5.0.7
WinXP SP2

--
And the Error is:

Code:
23:32:03,437 ERROR org.hibernate.util.JDBCExceptionReporter:78 - Lock wait timeout exceeded; try restarting transaction
0 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Lock wait timeout exceeded; try restarting transaction
23:32:03,437 ERROR org.hibernate.event.def.AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:297)
   at com.myapp.util.GenericEJB3DAO.flush(GenericEJB3DAO.java:44)
   at com.myapp.test.ReceiverServiceHibernateImplTest.testFindAll(ReceiverServiceHibernateImplTest.java:90)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
   at org.junit.runners.Suite.access$000(Suite.java:26)
   at org.junit.runners.Suite$1.run(Suite.java:93)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.runners.Suite.run(Suite.java:91)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
   ... 36 more
0 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:297)
   at com.myapp.util.GenericEJB3DAO.flush(GenericEJB3DAO.java:44)
   at com.myapp.test.ReceiverServiceHibernateImplTest.testFindAll(ReceiverServiceHibernateImplTest.java:90)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
   at org.junit.runners.Suite.access$000(Suite.java:26)
   at org.junit.runners.Suite$1.run(Suite.java:93)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.runners.Suite.run(Suite.java:91)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
   ... 36 more
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:300)
   at com.myapp.util.GenericEJB3DAO.flush(GenericEJB3DAO.java:44)
   at com.myapp.test.ReceiverServiceHibernateImplTest.testFindAll(ReceiverServiceHibernateImplTest.java:90)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
   at org.junit.runners.Suite.access$000(Suite.java:26)
   at org.junit.runners.Suite$1.run(Suite.java:93)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.runners.Suite.run(Suite.java:91)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:297)
   ... 30 more
Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
   ... 36 more


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 05, 2008 8:16 am 
Regular
Regular

Joined: Thu May 04, 2006 5:24 am
Posts: 55
Is it possible that I have called:

em.createQuery("delete from Receiver").executeUpdate();

without calling commit(), and that because of this transaction wasn't commited and I have locked database ?

One more thing, em.flush() is not working, when I call em.getTransaction().begin() and do somenthing, and then call flush() it doesn't write anything to database (but it generate SQL). If I call commit() then it does, but in that case if I try to call flush() again after commit() it generates an error that transaction doesn't exists ?

Thx.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 05, 2008 9:41 am 
Regular
Regular

Joined: Thu May 04, 2006 5:24 am
Posts: 55
Also, when I write one record in database in one @Test method:

em.getTransaction().begin();
em.persist(p1);
em.persist(p2);
em.getTransaction().commit();

It writes to the database corectly, but then when I want to read these in the other @Test method:

final List<Person> list = em.createQuery("from Person p") .getResultList();

assertEquals(2, list.size());

This list is empty, even that I have those two records in database ! Why is this ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 05, 2008 3:31 pm 
Regular
Regular

Joined: Thu May 04, 2006 5:24 am
Posts: 55
I found what was the problem, I didn't properly initialized Test objects in @Before method. Sorry.


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.