Hello,
I am updating/inserting a bunch of records in loop and after that transaction is being commit. I am using session.save(...) AND session.update(...) for the same.
If a record appears in the transaction which voilates constraints AND/OR due to some other reasons it throws exception then any attempt to use that session again throws exception. Is it the default behaviour of Hiberante session OR i am missing something.
I have a try catch block at record level, this block is a part of loop . Incase this block throws exception (Constraint Voilation currently)
Code:
try
{
session.save(user);
}
catch (Exception e)
{
e.printStackTrace();
}
then any furthur attemt to use session results in following exception
Code:
[5/6/09 9:26:55:531 IST] 0000001e SystemErr R org.hibernate.AssertionFailure: null id in com.app.portal.pojos.admin.User entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
I am very much aware that i should avoid exception to handle conditions prior to attempt of saving it but I want to handle it at record level without commiting after each record.
Anyone can please sugggest how can i keep session in stable state after the exception occurs.