Hi try to create batch execution list of object to SqlServer through Hibernate DAO . my DAO code as follows:
@Override
public void save(List<Tagihan> listTagihan) {
logger.debug("save list invoked");
Session session = sessionFactory.openSession();
try {
session.beginTransaction();
int counter = 0;
for (Tagihan tagihan : listTagihan) {
counter++;
session.save(tagihan);
if (counter % MAX_BATCH_SIZE == 0) {
// flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
session.getTransaction().commit();
logger.debug("save of list commited");
} catch (HibernateException exception) {
session.getTransaction().rollback();
logger.error(exception.getMessage(), exception);
throw exception;
} finally {
session.close();
}
}
While I'm trying to save the list of object some error occurred like this:
[7/12/10 18:34:29:125 ICT] 00000090 TagihanServic E id.co.hanoman.btnmw.spp.service.TagihanService updateStatusTagihan Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2353)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at id.co.hanoman.btnmw.spp.dao.TagihanDao.saveOrUpdate(TagihanDao.java:243)
at id.co.hanoman.btnmw.spp.service.TagihanService.updateStatusTagihan(TagihanService.java:131)
at id.co.hanoman.btnmw.spp.service.BillerTagihanSynchronizer.synchronize(BillerTagihanSynchronizer.java:30)
at id.co.hanoman.btnmw.spp.service.TagihanSynchronizerService.synchronize(TagihanSynchronizerService.java:64)
at id.co.hanoman.btnmw.spp.scheduler.TagihanSynchronizerWorker.run(TagihanSynchronizerWorker.java:44)
at com.ibm.ws.asynchbeans.J2EEContext$RunProxy.run(J2EEContext.java:268)
at java.security.AccessController.doPrivileged(AccessController.java:202)
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:768)
at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:222)
at com.ibm.ws.asynchbeans.ABWorkItemImpl.run(ABWorkItemImpl.java:159)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
[7/12/10 18:34:29:158 ICT] 00000090 TagihanSynchr E id.co.hanoman.btnmw.spp.service.TagihanSynchronizerService synchronize Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
java.lang.RuntimeException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at id.co.hanoman.btnmw.spp.service.TagihanService.updateStatusTagihan(TagihanService.java:134)
at id.co.hanoman.btnmw.spp.service.BillerTagihanSynchronizer.synchronize(BillerTagihanSynchronizer.java:30)
at id.co.hanoman.btnmw.spp.service.TagihanSynchronizerService.synchronize(TagihanSynchronizerService.java:64)
at id.co.hanoman.btnmw.spp.scheduler.TagihanSynchronizerWorker.run(TagihanSynchronizerWorker.java:44)
at com.ibm.ws.asynchbeans.J2EEContext$RunProxy.run(J2EEContext.java:268)
at java.security.AccessController.doPrivileged(AccessController.java:202)
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:768)
at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:222)
at com.ibm.ws.asynchbeans.ABWorkItemImpl.run(ABWorkItemImpl.java:159)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
Caused by: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2353)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at id.co.hanoman.btnmw.spp.dao.TagihanDao.saveOrUpdate(TagihanDao.java:243)
at id.co.hanoman.btnmw.spp.service.TagihanService.updateStatusTagihan(TagihanService.java:131)
... 9 more
my data about 30 records, When I use mysql as dbms, It works correctly, but if I use SQL Server 2000 those error occurred.
I need your help to solve my problem.
thanks