1 Reply Latest reply on Jun 12, 2008 9:36 AM by jaikiran pai

    How to implement a last modified or last user field ?

    johan micoud Newbie


      I'm trying to find a way to solve this tricky problem.
      I want to ensure that all modifications made on my EJB 3 entities are traced in a specific column (or field).

      I use a security context and I'd want to store the getSubject() and the current date in two fields.

      The idea is to get rid of the sessionContext (which contains the sessionContext.getCallerPrincipal().getName()) before any (real) update or persist operation.

      I have tried to implement PreUpdate and PostUpdate with a method containing lastModified=new Date(). But how to get the CallerPrincipal ?
      It is ok when I use a ThreadLocal and propagate my context between the session bean and the entity beans. But I use intensively Cascade merge/update operations. The @preUpdate method is called whenever the field is really stored or not.

      Is there a way to implement that use case as a simple SQL Trigger ?

      Thank a lot

      ps : I have tested the tips in the Auditing chapter in Java Persistence book without success