Global ORM EventHandling, Sessions, Arggh! :)

Forgive me in advance if this is rambly…

In my app, I have several entities for which I’d like to save some basic history tracking (e.g., user name was changed, product added to order, etc.). So the basic idea is something like this, in terms of entities:


To manage this in a sane way, I’m using an interceptor for the ORM events. There are 3 main things I want to track: preUpdate, postInsert, postDelete.

So what I do is to loop over a list of properties that I’ve pre-determined that I want to track. I loop over the intercepted entity and do what I need to do with the properties (e.g, get the values for inserts/deletes, compare for updates). I then create a new entity for the appropriate “history” entity, set the properties as needed, and save the new entity. This is all occurring within the appropriate ColdBox ORM events (e.g., ORMPostDelete ).

For ORMPreUpdate, this works without an issue. For ORMPostInsert and ORMPostDelete, however, I get lots of errors; for example, here’s one that I frequently run across: “org.hibernate.AssertionFailure: collection … was not processed by flush()”. I think what is happening is that when I try to use the intercepted entity as a part of the new “history” entity (e.g., as a foreign key db-side), there are collisions in hibernate, blah blah blah, and things blow up.

I’ve tried wrapping the creation/saving of the new history entity within its own session/transaction (as suggested elsewhere). This seems to have helped in some scenarios, but I still get errors when using the ColdBox proxy…so I get inconsistent behavior, depending upon how I am creating/deleting entities.

So enough of my complaining. My big question is whether there is a better way to go about doing this. I have tried to just revert to plain ol’ SQL queries, but I still get the same kinds of errors. Does anyone have any suggestions about 1.) a better approach to this kind of requirement or 2.) something I’ve missed that could resolve the issues I’m encountering.

I definitely appreciate any help anyone can provide. Thanks!

Hi Joel,

I’ve just been/going through this. You may want to take a look at my forum posting…!topic/coldbox/6g1n6dhNvU4%5B1-25%5D