[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6032) Executable actions, created inside lifecycle callbacks, are ignored during flush

Roman Boroday (JIRA) noreply at atlassian.com
Sun Mar 20 15:53:10 EDT 2011


Executable actions, created inside lifecycle callbacks, are ignored during flush
--------------------------------------------------------------------------------

                 Key: HHH-6032
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6032
             Project: Hibernate Core
          Issue Type: Bug
    Affects Versions: 4.0.0.Alpha1, 3.6.2, 3.6.1
            Reporter: Roman Boroday


When try to persist another entity inside event callback (for example create an audit record during PostPersist event), an executable action is being created, and it is added into the actions queue list, but ignored, because the for statement inside the ActionQueue class doesn't use the actual collection size, but an initial value instead:

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.getTransactionCoordinator().getJdbcCoordinator().executeBatch();
}

In my example PostPersist callback will be called inside the execute( (Executable) list.get( i ) ) call, and a new Executable will be created during merge() or persist() call, and added into the list collection, but when the for condition will be checked after execute (...) is done, it's going to use the initially calculated value, instead of the current list.size().

It seems like it is an expected behavior, but, first, if the size value changed in debug mode, it executes those added actions just fine, and, second, if it's a bad practice to create new entities inside lifecycle events callbacks, then maybe it would make sense to rise an exception, or show a warning when list size is changed to let developers know that they are doing something wrong? 

With the current implementation no errors or warnings are shown, but no new entities created either, leaving developers just guessing of what could go wrong. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list