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?