Hi, I'm trying to perform a massive update (now there are about 137000 records to update) and I'm doing it following Gavin King's instructions about batch processing (
http://blog.hibernate.org/cgi-bin/blosxom.cgi/Gavin%20King/batch.html).
I'm trying to commit a block of 10 updates (using batch_size 10) it works nicely until, after a while, I'm getting an error beginning a new transaction, error which I couldnt find in gooooogle and thought you may give me a hint:
(one last thing, we have sufficiently big rollback segments in our DB)
Hibernate version:2.1.8
Code between sessionFactory.openSession() and session.close():
Code:
(Class AlumnoService)
try
{
log.debug("Beginning update...");
AlumnoDAO dao = new AlumnoDAO();
String sQry = "select u.id from com.edesa.matri.persistence.Alumno u " +
"order by u.id";
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
ScrollableResults alumnos = session.createQuery(sQry).scroll();
tx.commit();
int count = 0;
Long id = null;
log.debug("Beginning Transaction...");
tx = session.beginTransaction();
while ( alumnos.next() ) {
id = (Long)alumnos.get(0);
Alumno item = (Alumno) session.load(Alumno.class, id);
log.debug("Updating record #" + count + " [" + item.getId() + "]");
// SOME UPDATES GO HERE
session.update(item);
count++;
if ( count % 10 == 0 ) {
//flush a batch of updates and release memory:
session.flush();
session.clear();
log.debug("committing...");
tx.commit();
log.debug("Beginning new Transaction...");
tx = session.beginTransaction();
}
}
log.debug("Doing last commit...");
// commits last transaction.
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() )
tx.commit();
log.debug("Process ended succesfully.");
}
catch(Exception e)
{
log.debug("Error in the Process!");
HibernateUtil.rollbackTransaction();
throw new BusinessException(ErrorMessage.UPDATE_FAILURE + ErrorMessage.causa(e));
}
finally
{
HibernateUtil.closeSession();
}
Name and version of the database you are using:Oracle 9The generated SQL (show_sql=true):Exception + Debug level Hibernate log excerpt:Code:
13:35:57,497 DEBUG BatcherImpl:28 - Adding to batch
13:35:57,497 DEBUG BatcherImpl:50 - Executing batch size: 10
13:35:57,497 DEBUG BatcherImpl:58 - success of batch update unknown: 0
13:35:57,497 DEBUG BatcherImpl:58 - success of batch update unknown: 1
13:35:57,497 DEBUG BatcherImpl:58 - success of batch update unknown: 2
13:35:57,497 DEBUG BatcherImpl:58 - success of batch update unknown: 3
13:35:57,497 DEBUG BatcherImpl:58 - success of batch update unknown: 4
13:35:57,513 DEBUG BatcherImpl:58 - success of batch update unknown: 5
13:35:57,513 DEBUG BatcherImpl:58 - success of batch update unknown: 6
13:35:57,513 DEBUG BatcherImpl:58 - success of batch update unknown: 7
13:35:57,513 DEBUG BatcherImpl:58 - success of batch update unknown: 8
13:35:57,513 DEBUG BatcherImpl:58 - success of batch update unknown: 9
13:35:57,513 DEBUG BatcherImpl:210 - done closing: 1 open PreparedStatements, 1 open ResultSets
13:35:57,513 DEBUG BatcherImpl:272 - closing statement
13:35:57,513 DEBUG SessionImpl:2844 - post flush
13:35:57,513 DEBUG AlumnoService:486 - Haciendo commit...
13:35:57,513 DEBUG JDBCTransaction:59 - commit
13:35:57,513 DEBUG SessionImpl:2266 - flushing session
13:35:57,513 DEBUG SessionImpl:2459 - Flushing entities and processing referenced collections
13:35:57,513 DEBUG SessionImpl:2800 - Processing unreferenced collections
13:35:57,513 DEBUG SessionImpl:2814 - Scheduling collection removes/(re)creates/updates
13:35:57,513 DEBUG SessionImpl:2290 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
13:35:57,513 DEBUG SessionImpl:2295 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
13:35:57,513 DEBUG SessionImpl:2379 - executing flush
13:35:57,513 DEBUG SessionImpl:2844 - post flush
13:35:57,513 DEBUG SessionImpl:594 - transaction completion
13:35:57,513 DEBUG AlumnoService:488 - Beginning New Transaction...
13:35:57,513 DEBUG JDBCTransaction:37 - begin
13:35:57,513 DEBUG JDBCTransaction:41 - current autocommit status:false
13:35:57,622 DEBUG JDBCExceptionReporter:49 - error performing next()
java.sql.SQLException: ORA-01555: snapshot too old: rollback segment number 5 with name "_SYSSMU5$" too small
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:1198)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:277)
at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:2086)
at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:2060)
at oracle.jdbc.driver.ScrollableResultSet.next(ScrollableResultSet.java:347)
at net.sf.hibernate.impl.ScrollableResultsImpl.next(ScrollableResultsImpl.java:94)
at com.edesa.matri.service.AlumnoService.crearFoneticos(AlumnoService.java:456)
at com.edesa.matri.test.services.AlumnoTest.testCrearFoneticos(Unknown Source)
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 com.edesa.matri.test.TestCase.runTest(Unknown Source)
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 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:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
13:35:57,622 WARN JDBCExceptionReporter:57 - SQL Error: 1555, SQLState: 72000
13:35:57,622 ERROR JDBCExceptionReporter:58 - ORA-01555: snapshot too old: rollback segment number 5 with name "_SYSSMU5$" too small
13:35:57,622 DEBUG AlumnoService:503 - Error in the Process!
13:35:57,622 DEBUG HibernateUtil:? - Cerrando la sesion de este Thread.
13:35:57,622 DEBUG SessionImpl:576 - closing session
13:35:57,622 DEBUG SessionImpl:3371 - disconnecting session
13:35:57,622 DEBUG BatcherImpl:210 - done closing: 0 open PreparedStatements, 0 open ResultSets
13:35:57,622 DEBUG BatcherImpl:272 - closing statement
13:35:57,622 DEBUG DriverManagerConnectionProvider:120 - returning connection to pool, pool size: 1
13:35:57,622 DEBUG HibernateUtil:? - Sesion cerrada.
13:35:57,653 DEBUG HibernateUtil:? - Conexion nula o ya habia sido cerrada.
13:35:57,653 ERROR AlumnoTest:? - Error en la prueba.
Thanks in advance for any pointer. :)