Hi everybody, need your help please... My purpose is to delete entities with Hibernate without actually delete those entities from database. I.e., to mark those entities as deleted (e.g. using Boolean flag ‘isDeleted’ within all entities base class). Moreover, I would like to take advantage of the cascading power built in Hibernate so any entity that is being deleted will cascade the operation to its children (“customer” and collection of “orders”: “orders” should be deleted too) After 2 days (!) searching the WEB for an elegant solution, I realized that I need to implement and register the Delete event listener. And so I did. First thing I have learned is that using Interceptors cannot help me here. Those are called from within the event (in my case is delete), letting the user a chance to do something (e.g. update) but the deletion is going to be done anyway. Next… So, I override the onDelete method of DefaultDeleteEventListener class trying to modify it so deletion will not occur. I have noticed that the deletion is done by deleteEntity method. Overriding that method seems to do what I’m looking for but this method cannot be override (declared as final). Trying to override invokeDeleteLifecycle function (the only one that returns Boolean) and return ‘true’ instead of ‘false’ did the job but without cascading (the ‘cascading’ stopped immediately when returning ‘true’ from the function). I have also tried to clean the ActionQueue (within the event), but its clear method clears everything (not just the deletion list, so any desired update is cleared too) I was trying also to override any Flush event. Any modification just makes me more depressed… My Question: Is there a way to do what I am looking for??? (Deletion of entities without actually delete, just mark it as deleted and very very important – do the “delete” cascading either). BTW: We are using Hibernate 3.3.2 (not using Entity Manager), jBoss 4.x Any idea/suggestion is appreciated! Simon (the frustrated)
|