-->
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.  [ 6 posts ] 
Author Message
 Post subject: BatchUpdateException... how to I solve this?
PostPosted: Fri Sep 10, 2004 3:35 pm 
Newbie

Joined: Fri Sep 10, 2004 2:30 pm
Posts: 2
Hibernate version:

2.1

Mapping documents:

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

<hibernate-mapping>

<class name="com.sony.model.JobsContent" table="jobs_content" batch-size="30">
<cache usage="read-write"/>

<id name="id" column="H1" unsaved-value="0">
<generator class="sequence">
<param name="sequence">HIBERNATE1</param>
</generator>
</id>
<property name="jobId" column="JOB_ID" not-null="true" />
<property name="tagId" column="TAG_ID" not-null="true"/>
<property name="value" column="VALUE" type="com.sony.StringClobType2"/>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

session = sessionFactory.openSession(conn);
...yadda...
finally{
session.close()
}

Full stack trace of any exception that occurs:

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sunnyside.ThreadManager.tunnelException(ThreadManager.java:113)
at com.sony.sunnyside.ThreadManager.execute(ThreadManager.java:41)
at com.sony.sunnyside.ActionCallBack.execute(ActionCallBack.java:20)
at com.sony.sunnyside.Dispatcher.handleRequest(Dispatcher.java:85)
at com.sony.sunnyside.Dispatcher.doGet(Dispatcher.java:59)
at com.sony.sunnyside.Dispatcher.doPost(Dispatcher.java:106)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:31)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
... 1 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:31)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
... 5 more
Caused by: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:288)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
... 9 more
Caused by: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
... 10 more
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
----------------------------------------------------------
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:31)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:31)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
... 5 more
Caused by: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:288)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
... 9 more
Caused by: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
... 10 more
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
----------------------------------------------------------
java.lang.RuntimeException: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:31)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:288)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
... 9 more
Caused by: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
... 10 more
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
----------------------------------------------------------
java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:288)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
at java.lang.Thread.run(Thread.java:534)
Caused by: net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
... 10 more
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
----------------------------------------------------------
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
----------------------------------------------------------
java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1807)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.sony.sandbar.HermesSandbar$10.trans(HermesSandbar.java:284)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.sandbar.HermesSandbar.getATag(HermesSandbar.java:297)
at com.sony.content.data_access.TagsConcern.save(TagsConcern.java:138)
at com.sony.content.HermesContentController$1.trans(HermesContentController.java:278)
at com.sony.sandbar.TransactionBase.execute(TransactionBase.java:27)
at com.sony.content.HermesContentController.save(HermesContentController.java:287)
at com.sony.content.display.ContentSummary$5.execute(ContentSummary.java:197)
at com.sony.sunnyside.ActionCallBack$1.run(ActionCallBack.java:23)
at com.sony.sunnyside.ThreadManager$1.run(ThreadManager.java:23)
at java.lang.Thread.run(Thread.java:534)


Name and version of the database you are using:

Oracle 8i

The generated SQL (show_sql=true):

(except)
Hibernate: select tags0_.TAG_ID as TAG_ID, tags0_.DEFAULT_VALUE as DEFAULT_2_, tags0_.STATUS as STATUS, tags0_.TYPE as TYPE, tags0_.HTMLEDIT as HTMLEDIT, tags0_.CSS_BASE as CSS_BASE, tags0_.HTMLEDIT_DEFAULT as HTMLEDIT7_ from tags tags0_ where (tags0_.TAG_ID=? )
Hibernate: select jobstempla0_.H1 as H1, jobstempla0_.TEMPLATE_ID as TEMPLATE2_, jobstempla0_.JOB_ID as JOB_ID, jobstempla0_.VALUE as VALUE, jobstempla0_.FORMAT as FORMAT, jobstempla0_.TYPE as TYPE from jobs_templates jobstempla0_ where (jobstempla0_.JOB_ID=? )and(jobstempla0_.FORMAT=? )and(jobstempla0_.TYPE=? )
Hibernate: select jobstempla0_.H1 as H1, jobstempla0_.TEMPLATE_ID as TEMPLATE2_, jobstempla0_.JOB_ID as JOB_ID, jobstempla0_.VALUE as VALUE, jobstempla0_.FORMAT as FORMAT, jobstempla0_.TYPE as TYPE from jobs_templates jobstempla0_ where (jobstempla0_.JOB_ID=? )and(jobstempla0_.FORMAT=? )and(jobstempla0_.TYPE=? )
Hibernate: select language0_.LANGUAGE_ID as x0_0_, language0_.LANGUAGE_NAME as x1_0_ from languages language0_ order by language0_.LANGUAGE_NAME
Hibernate: select jobsconten0_.H1 as H1, jobsconten0_.JOB_ID as JOB_ID, jobsconten0_.TAG_ID as TAG_ID, jobsconten0_.VALUE as VALUE from jobs_content jobsconten0_ where (jobsconten0_.JOB_ID=? )and(jobsconten0_.TAG_ID=? )
Hibernate: update jobs set LANGUAGE_ID=?, STATUS=?, COMPANY_ID=?, USERNAME=?, LAST_USER=?, PREVIEW_EMAIL_ADDRESS=?, CAMPAIGN_CODE=? where JOB_ID=?
Hibernate: update jobs_content set JOB_ID=?, TAG_ID=?, VALUE=? where H1=?


Debug level Hibernate log excerpt:

Don't know what this is.



---------------------------------------------------------------------

Ok, I am about as frustrated as a person can get. All I am doing is a simple insert into my database. If the row exists, I expect Hibernate to update it. Normal stuff.

This may be related to my imperfect understanding of transaction handling in Hibernate. In this particular case, before I attempt to save() into jobs_content, I read the row first to make sure it is known to me. Oddly, the problems happens when I try to read a row. Perhaps it has something to do with a row I have already batched up.

I absolutely have no idea why this should be failing. All the rows I am save()ing should already exist in the database table. So it should be updating in all cases - and with no inserts, I don't expect a dup key failure. I singled stepped through my code to make sure the keys (job_id + tag_id) are correct.

How do I proceed?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 3:44 pm 
Newbie

Joined: Fri Sep 10, 2004 2:30 pm
Posts: 2
Looking in my resin logs, I also see this:

SEVERE: Could not synchronize database state with session

Looks important ;-) but I don't know if it is the cause or a side-effect.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 4:27 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Looking in your logs, I also see:

Code:
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SPCDEVODS.SYS_C008588) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at...


This is obviously the root cause of the BatchUpdateException...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 4:43 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Quote:
I absolutely have no idea why this should be failing. All the rows I am save()ing should already exist in the database table. So it should be updating in all cases - and with no inserts, I don't expect a dup key failure.


This looks like a problem. save() can be thought of as your insert function. This will always try to insert a new object. If you are wanting to update an object that was loaded in the SAME session, do nothing. When you call session.flush() ( probably implicitly with transaction.commit() ) hibernate will detect you have modified the object and generate an update automagically. ( It compares what the object looked like when it was loaded with what it looks like now, any differences cause an update ).

If you loaded the object in a DIFFERENT session you can reattach it to the session for an update by using session.update().


Top
 Profile  
 
 Post subject: Re: BatchUpdateException... how to I solve this?
PostPosted: Fri Sep 10, 2004 11:24 pm 
Newbie

Joined: Fri Sep 10, 2004 10:53 pm
Posts: 3
tonyennis wrote:
Hibernate version:
I absolutely have no idea why this should be failing. All the rows I am save()ing should already exist in the database table. So it should be updating in all cases - and with no inserts, I don't expect a dup key failure. I singled stepped through my code to make sure the keys (job_id + tag_id) are correct.

Uniqueness constraint could be the issue.

Try using session.saveOrUpdate(Object). Hibernate will determine whether to insert or update depending on whether the unique identifier of your object already exists in the database or not.

_________________
- SPS


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 11, 2004 12:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Try using session.saveOrUpdate(Object). Hibernate will determine whether to insert or update depending on whether the unique identifier of your object already exists in the database or not.

Not completely correct. Hibernate actually basis this decision on the configured unsaved-value attribute options. It does not actually query the DB to determine if the row physically exists.

For the class in question:
<id name="id" column="H1" unsaved-value="0">

If the entity instance's id value is zero, Hibernate considers this a brand new transient instance and attempt to insert it on saveOrUpdate().


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