-->
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.  [ 5 posts ] 
Author Message
 Post subject: Could not execute JDBC batch update
PostPosted: Tue Apr 19, 2005 3:26 pm 
Newbie

Joined: Tue Sep 14, 2004 11:18 am
Posts: 10
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


Top
 Profile  
 
 Post subject: Re: Could not execute JDBC batch update
PostPosted: Tue Apr 19, 2005 10:22 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
can you provide your mapping files ?


Top
 Profile  
 
 Post subject: Mapping
PostPosted: Wed Apr 20, 2005 12:56 am 
Newbie

Joined: Tue Sep 14, 2004 11:18 am
Posts: 10
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:c:/x/data/test</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"> </property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<property name="hibernate.connection.autocommit">false</property>

<mapping resource="resources/Human.hbm.xml"/>

</session-factory>
</hibernate-configuration>




<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="tecaf.basic.Human" table="HUMANS" lazy="false">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="level" type="int" />
<property name="lastName" not-null="true"/>
<property name="firstName" not-null="true"/>
<property name="email" not-null="true" unique="true" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Mapping
PostPosted: Wed Apr 20, 2005 8:28 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
I've run a test using the information provided and I don't receive any exceptions. The only thing I wasn't able to duplicate is your initRandomHuman() method so is it possible that there is actually a data issue that's causing this exception ?

I was able to recreate your exception using
Code:
h.setEmail(new Date().getTime() + "");


And the Thread.sleep(1000) fixed this because now obviously the getTime() would never be duplicated.

Using
Code:
h.setEmail(Math.random()+ "")
this problem did not exist.


Hope this helps.


Top
 Profile  
 
 Post subject: data error: solved
PostPosted: Wed Apr 20, 2005 9:10 am 
Newbie

Joined: Tue Sep 14, 2004 11:18 am
Posts: 10
Ouch, you are right. I actually use
human.setEmail("" + System.currentTimeMillis());
for the generation of my random data, but that is still too fast. Reducing the sleep to 10ms solves the problem.
Thanks a lot for the effort!

Stephan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.