-->
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.  [ 1 post ] 
Author Message
 Post subject: Batch Update Error
PostPosted: Fri Jun 11, 2010 5:26 pm 
Newbie

Joined: Fri Jun 11, 2010 4:56 pm
Posts: 1
I am using Hibernate with JBoss Seam. I have a page with a datatable of courses. You can "remove" a course from the table or "add" a course to the table, but the changes are not made to the database until you "save" (see code below).
Code:
@Scope(ScopeType.CONVERSATION)
@Transactional
public class CoursePage implements Serializable {

   CourseHome courseHome;
   EntityManager entityManager;
   
   public void add() {
      ...
      entityManager.persist(courseHome.getInstance());
   }

   public void remove(int id) {
      ...
      courseHome.setId(id);
      entityManager.remove(courseHome.getInstance());
   }
   
   @End
   public void save() {
      entityManager.flush();
   }
}

However, when I first remove a course and then add the SAME course back in and then save, I get the following error:
Code:
17:01:02,555 WARN  [JDBCExceptionReporter] hdu SQL Error: -4228, SQLState: null
17:01:02,556 ERROR [JDBCExceptionReporter] hdu [jcc][t4][102][10040][3.50.152] Non-atomic batch failure.  The batch was submitted, but at least one exception occurred on an individual member of the batch.
Use getNextException() to retrieve the exceptions for specific batched elements. ERRORCODE=-4228, SQLSTATE=null
17:01:02,556 WARN  [JDBCExceptionReporter] hdu SQL Error: -803, SQLState: 23505
17:01:02,556 ERROR [JDBCExceptionReporter] hdu Error for batch element #1: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505, SQLERRMC=2;DB2INST1.PERSON_BUILDING_ACCESS_LEVEL, DRIVER=3.50.152
17:01:02,557 ERROR [AbstractFlushingEventListener] hdu Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
...
Caused by: com.ibm.db2.jcc.b.em: [jcc][t4][102][10040][3.50.152] Non-atomic batch failure.  The batch was submitted, but at least one exception occurred on an individual member of the batch.
Use getNextException() to retrieve the exceptions for specific batched elements. ERRORCODE=-4228, SQLSTATE=null
...

I also noticed in the logs that the inserts always come before the deletes, which may be the reason for the ConstraintViolation (because it may be trying to insert a course that's already in the database). If so, is there a way to commit the transaction in the order that the operations where done instead of doing all inserts before the deletes?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.