Hi,
I use version 3.0.1 with HSQLDB and continuosly encounter when executing fast SQL statements. I broke it down to a very simple example, happens in different circumstances too, though:
"Could not execute JDBC batch update"
This code works fine with the sleep, but wihout the exception occurs:
for (int i = 0; i < 10; i++)
{
Human h = initRandomHuman();
manager.store(h);
humans.add(h);
Thread.sleep(1000);
}
where the manager executes:
public void store(Human human)
{
Transaction tx = session.beginTransaction();
session.save(human);
tx.commit();
}
This appears to be a timing problem. Seems, that Hibernate tries to optimize and executes all inserts in one "batch"? Any way I can disable this? Or, even better, make it work? The docu states that I should flush() and clear() the session, this did not help, though.
I have a low traffic application, the problems only occur while testing, not in production. Not yet, anyway.
Hibernate: insert into HUMANS (level, lastName, firstName, email, uid) values (?, ?, ?, ?, ?)
Hibernate: insert into HUMANS (level, lastName, firstName, email, uid) values (?, ?, ?, ?, ?)
WARN [main] (JDBCExceptionReporter.java:57) - SQL Error: 0, SQLState: null
ERROR [main] (JDBCExceptionReporter.java:58) - failed batch
ERROR [main] (AbstractFlushingEventListener.java:277) - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at tecaf.basic.HumanManager.store(HumanManager.java:27)
at test.tecaf.basic.HumanManagerTest.testList(HumanManagerTest.java:79)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
... 24 more
|