-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Deletions executed within a PreDeleteListener being lost
PostPosted: Mon Sep 26, 2005 4:36 pm 
Newbie

Joined: Wed Sep 14, 2005 7:27 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

I can provide an application-independent test case as well as a patch for this issue, but I'm posting here first as a sanity check. If I am misusing the event hook functionality, I would be appreciative of any suggestsions on how otherwise I might go about what I am attempting to do here.

This is in the context of a web service using POJOs in a Java Servlet.

To handle the deletion or update of one or more Foo record, we have implemented in the application some fairly complex on update and on delete logic to synchronize 0 or more corresponding Bar records. This is primarily a matter of synchronizing date ranges: updating the date ranges of Bar records which overlap Foo records such that every day in the Bar record range interesects a Foo record, and deleting those Bar records which fall outside the date range of every Foo record.

Both Foo and Bar use Hibernate for persistence.

We have created our own DeleteEventListener and UpdateEventListener to implement this constraint logic.

So to the point: consider the condition C1, where a Foo entity is being deleted, where there is a Bar entity contained entirely by this Foo entity. In response to the deletion of the Foo entity, we want to delete the Bar entity.

So we have something like:
Code:
public boolean onPreDelete(PreDeleteEvent event) {
    boolean value = super.onPreDelete(event);
    if (!value) {
        if (event.getEntity() instanceof Foo) {
            if ([C1]) {
                 [session.delete B1 where B1 is the contained Bar record]
            }
        }
    }
    return value;
}


I can verify that the action to delete B1 is placed in the session's ActionQueue. Yet it is never executed.

I believe this is because of the following logic in ActionQueue:
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();
   }


I believe the loop should be checking the size of the queue every iteration. As it stands, the new deletion (the deletion of B1) added to the queue in response to the PreDeleteEvent will never be processed, because it is at an index in list greater than size - 1. The action is lost because list.clear() (where list is deletions) is executed after iterating over the elements initially in the list.

Also in ActionQueue:
Code:
public void executeActions() throws HibernateException {
      executeActions( insertions );
      executeActions( updates );
      executeActions( collectionRemovals );
      executeActions( collectionUpdates );
      executeActions( collectionCreations );
      executeActions( deletions );
   }


Because it is also possible that we would add an update action (updating a corresponding Bar record) in response to a PreDeleteEvent for a Foo object, this block or method would need to be executed possibly repeatedly until it is true that all queues are empty. This could be either a while loop in this method having this as its condition, or a loop containing the invocation of this method having this as its condition.

Upon making these changes Hibernate performs as I expected it would in these scenarios.

So my quesiton for you is, is my understanding of the expected behavior correct, or am I somehow misusing the event framework?

Or let me know if you require additional configuration information or examples.

Thanks!

--dircha


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 7:36 pm 
Newbie

Joined: Wed Sep 14, 2005 7:27 pm
Posts: 2
The defect reporting page suggests that a defect report must receive approval here before it will even be considered. I am making an effort to comply with these instructions.

I believe the description of the issue and the correction I suggest should be more than satisfactory for anyone familiar with the codebase to give a short answer as to whether I am correctly interpreting the (completely undocumented) intended behavior of the event framework in this regard, and whether the suggested correction is consistent with the intended behavior.

As I understand the intended behavior, the changes I suggest do resolve the issue I encountered. I have confirmed this locally.

If no one official is able to give this post consideration, I would very much appreciate at least anyone at all familiar with the codebase offering feedback. At the very least I can then for the time being proceed using a locally modified source tree with some degree of comfort.

Thank you!

--dircha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.