Hibernate version:
Hibernate-Version: 3.1.3
Hi,
I have encountered a problem with the class org.hibernate.engine.ActionQueue and I don't see a good resolution.
When I try to delete an entity from the database and a constraint error occurs I do a transaction rollback. In my case after such an error has happened I have to begin a new transaction and perform a list(). The problem is that when making the list() Hibernate comes up with an AssertionFailure("possible nonthreadsafe access to session"). This failure comes from
org.hibernate.action.EntityDeleteAction.execute():83
From what I understood the entity was removed from the persistence context when the delete was called and when the execute() is called again the entry is not found:
Code:
EntityEntry entry = persistenceContext.removeEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible nonthreadsafe access to session" );
}
I was wondering why the delete action is called for the list() and found out that the deletions list that contains SQLs to execute is left behind after the call to delete.
In
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions()
we have the following line:
session.getActionQueue().executeActions();
This calls org.hibernate.engine.ActionQueue.executeActions() that contains
executeActions(deletions):
Code:
private void executeActions(List list) throws HibernateException {
int size = list.size();
for ( int i = 0; i < size; i++ ) {
execute( (Executable) list.get(i) );
}
list.clear();
session.getBatcher().executeBatch();
}
From what I see here when my delete sql is rejected due to a constraint violation the deletions list is not cleared. When I scanned through the usages I didn't find other occurrences of clear(). I guess that there is some problem with the execution flow and maybe the clear() should also be made at some other point.
Why is the deletions collection not cleared when I have begun a new transaction?
Do I have to call a clear by hand after an unsuccessful delete?
Something like:
Code:
((EventSource)HibernateUtils.currentSession()).getActionQueue().clear();
or
Code:
HibernateUtils.currentSession().clear();