My application which uses Hibernate works fine until a large number of records are inserted into the database tables. I don't think, therefore, that this is a mapping problem or some trivial misuse of Hibernate. It's probably a DB2 specific issue, so I'm hoping that someone who uses DB2 and Hibernate may be able to shed some light on the issue.
The stack trace below pretty much summarizes the problem. I read in records from a table (unmapped to hibernate) and turn each record into a number of Java objects that are mapped by Hibernate. Then I save the root object and move on to the next input record. If I run less than about 15,000 input records everything works fine. Over that I will eventually get the error below. Our strategy so far has been to rebind the DB2 packages that the error complains about. But we have now rebound hundreds of packages and the result is just that it takes longer for the error to occur. As you can see from the INFO statement 57634 records were processed. I could rebind the package it is complaining about and maybe that number would go up to 65000, but eventually I will get this error. I need to process around 550,000 records.
My manager and the DBA are so frustrated with this issue that they want rip Hibernate out of the picture, which, at this point, I don't have much of a defense against.
I am wondering if the problem could have anything to do with Hibernate's use of connections, transactions, statements, etc. So far I've tried flushing and clearing the session periodically; flushing and clearing after each object is save; evicting each object after it is save; committing the transaction after a certain number of input records are processed and starting a new one; using and not using a connection pool (c3p0). None of these solve the problem.
Code:
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -805, SQLState: 51002
ERROR org.hibernate.util.JDBCExceptionReporter - DB2 SQL error: SQLCODE: -805, SQLSTATE: 51002, SQLERRMC: NULLID.SYSLH2 96 0X5359534C564C3031
INFO org.egcrc.cfr.proposing.LinkingJob - Linking Job created 57634 normalized records and 172902 appearances.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [org.egcrc.cfr.normalized.No rmalizedRecord]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2093)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2573)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:47)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateE ventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.jav a:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener. java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.jav a:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at org.egcrc.cfr.persistence.HibernateObjectManager.saveObject(Unknown Source)
at org.egcrc.cfr.proposing.LinkingJob.normalizeSourceRecords(Unknown Source)
at org.egcrc.cfr.proposing.LinkingJob.normalizeSourceRecords(Unknown Source)
at org.egcrc.cfr.proposing.LinkingJob.main(Unknown Source)
Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -805, SQLSTATE: 51002, SQLERRMC: NULLID.SYSLH296 0X5 359534C564C3031
at com.ibm.db2.jcc.a.hd.e(hd.java:1659)
at com.ibm.db2.jcc.c.jb.p(jb.java:684)
at com.ibm.db2.jcc.c.jb.h(jb.java:152)
at com.ibm.db2.jcc.c.jb.a(jb.java:43)
at com.ibm.db2.jcc.c.w.a(w.java:30)
at com.ibm.db2.jcc.c.cc.g(cc.java:160)
at com.ibm.db2.jcc.a.hd.n(hd.java:1215)
at com.ibm.db2.jcc.a.id.gb(id.java:1780)
at com.ibm.db2.jcc.a.id.d(id.java:2255)
at com.ibm.db2.jcc.a.id.Y(id.java:537)
at com.ibm.db2.jcc.a.id.executeUpdate(id.java:520)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:33)
... 19 more
Hibernate 3.2; DB2 8.2; Java 1.5.
Thanks.