Hi,
I am regularly experiencing the following bug:
Code:
[net.sf.hibernate.AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
net.sf.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2630)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2454)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2447)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2249)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228)
at za.co.quirk.milk.action.dairy.DairyImportAction.execute(DairyImportAction.java:101)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
....
My Hibernate version is 2.1.3. The database is MySQL 4.0.18. Here is an excerpt from the mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="za.co.quirk.milk.model.Contact" table="contact">
<id name="id">
<generator class="native"/>
</id>
....
</class>
</hibernate-mapping>
The code excerpt:
Code:
for( int row = 2; ( line = parser.getNextLine() ) != null; row++ )
{
.....
Contact contact = (Contact)addressMap.get( email );
if( contact == null )
{
contact = new Contact();
}
.....
session.saveOrUpdate( contact );
if( row % 256 == 0 )
{
session.flush();
}
}
The flush every 256 rows is done to avoid the session becoming too "loaded" with unsaved objects, as the number of rows can be large. Is this "unsafe use of the session" as suggested in the exception?
Thanks,
Craig