Hallo,
ich versuche gerade mit Hibernate anzufangen. Ich versuche meine Applikation in JUnit Tests zu testen. In den zweiten Test versuche in einem Batch Delete die Tabelle wieder zu löschen. Dabei bekomme einen Lock wait timeout. Das dürfte doch eigentlich doch nur vorkommen wenn eine Transaction noch nicht comitted wurde. Was mach ich da falsch?
Hibernate version:
3.2.6.GA
Code between sessionFactory.openSession() and session.close():
Code:
public class FencerTest {
private AnnotationConfiguration annotationConfiguration;
private SessionFactory sessionFactory;
@Before
public void setup() {
this.annotationConfiguration = new AnnotationConfiguration();
this.annotationConfiguration.configure();
this.sessionFactory = annotationConfiguration.buildSessionFactory();
}
@Test
public void saveGetFencer() {
Calendar birthdate = Calendar.getInstance();
birthdate.set(Calendar.DAY_OF_MONTH, 5);
birthdate.set(Calendar.MONTH, 5);
birthdate.set(Calendar.YEAR, 1990);
Fencer maya = new Fencer("Maya", "Claßen", birthdate.getTime());
Session session = sessionFactory.openSession();
session.setFlushMode(FlushMode.AUTO);
Transaction transaction = session.beginTransaction();
session.save(maya);
assertNotNull(maya.getId());
maya = (Fencer) session.load(Fencer.class, maya.getId());
assertNotNull(maya);
assertEquals("Maya", maya.getFirstName());
Fencer fencer = (Fencer) session.get(Fencer.class, 1011);
assertNull(fencer);
Query query = session.createQuery("SELECT f FROM Fencer f WHERE f.firstName LIKE 'M%'");
List<Fencer> fencers = query.list();
assertEquals(1, fencers.size());
transaction.commit();
session.close();
}
@After
public void tearDown() {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("DELETE FROM Fencer");
query.executeUpdate();
transaction.commit();
session.close();
this.sessionFactory.close();
}
}
Full stack trace of any exception that occurs:Code:
org.hibernate.exception.GenericJDBCException: could not execute update query
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.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at business.test.FencerTest.tearDown(FencerTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.MethodRoadie.runAfters(MethodRoadie.java:138)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:92)
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.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.SQLException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 25 more
Name and version of the database you are using:MySQL 5.0
Debug level Hibernate log excerpt:Code:
20:03:32,021 DEBUG SQL:401 - insert into Fencer (birthDate, firstName, lastName) values (?, ?, ?)
20:03:32,068 DEBUG SQL:401 - select fencer0_.id as id0_0_, fencer0_.birthDate as birthDate0_0_, fencer0_.firstName as firstName0_0_, fencer0_.lastName as lastName0_0_ from Fencer fencer0_ where fencer0_.id=?
20:03:32,318 DEBUG SQL:401 - select fencer0_.id as id0_, fencer0_.birthDate as birthDate0_, fencer0_.firstName as firstName0_, fencer0_.lastName as lastName0_ from Fencer fencer0_ where fencer0_.firstName like 'M%'
20:03:32,365 DEBUG SQL:401 - delete from Fencer
20:04:23,630 WARN JDBCExceptionReporter:77 - SQL Error: 1205, SQLState: 41000
20:04:23,630 ERROR JDBCExceptionReporter:78 - Lock wait timeout exceeded; try restarting transaction