I am building an History system in an application, and I'm facing the same problem. Here is my concept. For each object that is marked to be "Historizable", we must always copy the integrality of the columns in another database, in a schema that is almost the same as the original(plus some columns saying the type of manipulation, the date etc). In my history version of the database, the ids of the objects aren't primary keys, but are logged. Foreign keys are also copied since we need to be able to query this database almost as if it were the current database.
For doing this, my strategy was to capture, in example, my insert with postInsert event, then reconstruct a select string that will select all the columns of the newly inserted object, and, based on the result, construct and execute an insert String with the additionnal information.
The idea isn't perfect, but it would have worked if the postInsert did really trigger after the data has been inserted in the database.
I also tried with interceptors, but I'm facing another problem : All the object aren't in the database when postFlush is called. In exaqmple, I have a parent object and a child object (a set on childObject in the parent object). All of these aren't already in the database so this is just all inserts. PostFlush is called an I loop through the Iterator of the "flushed" objects, and then making selects and building inserts for each ones. The most bizar thing is that it work for my child objects(the are read from the database then inserted in the other), but not for my parent Object : At the time of the postFlush, the select string is constructed, executed, but return nothing, even if at the end of the entire process the data as been correctly inserted in the current database. Anyone could help with suggestions on this ? The solution to my problem seems to be in the Hibernate 3.1 postCommitXXX, but since it is in beta version, I cannot allow myself to mount it in production. Do anyone know when the 3.1 version will be released ?
|