2 Replies Latest reply on Feb 18, 2008 11:45 AM by mars1412

    newbie: automatically writing auditing data

      I want to have basic auditing: just need to know who changed/created the entity and when

      I created a History component, that I simply include into the entities, that I want to audit.
      I use hibernate.ejb.event.post-insert and hibernate.ejb.event.post-update event listeners, to write the history data.

      This works, but I noticed that, when I persist a new (simple) entity, the post-insert event is triggered, which will change the history data, triggering an update and the post-update event will change the history data again, triggering another update

      is it just the wrong event that I am using, or is this way completely wrong?

        • 1. Re: newbie: automatically writing auditing data

          to clarify my question:
          is there smth. like hibernate.ejb.event.pre-update and hibernate.ejb.event.pre-insert?

          • 2. Re: newbie: automatically writing auditing data

            ok, I just got 1 step further

            I used the <property name="hibernate.ejb.event.post-insert" ..> event listener and assigned my class, that exetended: org.hibernate.ejb.event.EJB3PostInsertEventListener as already stated above, this works, but 'post' is the wrong time

            I could not find some EJB3PreInsertEventListener and also found nothing in org.hibernate.event.*. This was because code completion in JBDS really works, and only showed me classes, that I could extend from.
            That was, why I didn't see, the org.hibernate.event.PreInsertEventListener INTERFACE: I'm a dump noob...

            so my new class now implements the preInsert and preUpdate interfaces and I am quite happy, but it still does not work, as expected when inserting a new record:
            1) the preInsert event is called: I set the history on my entity
            2) hibernate makes an insert statement, but the parameters for the created part of the history are empty (although they have been set in my eventlistner: checked in the debugger)
            3) then the preUpdate event is called: my preUpdate event will also set the update part of the history (create is already set)
            4) now hibernate makes an update statement of the new entity and updates both parts of the history - so after inserting the entity, created and updated are set, which is of course not what I want

            any ideas why this happens?

            • why does the insert statement not show the data I've set on preInsert?
            • why is another update statement generated?