3 Replies Latest reply on Oct 21, 2005 5:53 AM by epbernard

    How to check if entity bean is changed

    atodorov

      If you call the merge() method, but the passed entity object has no changes, jboss/hibernate does not try to store (update) it at all. This is cool, but does anybody know if I can check which fields of a bean are modified (if any) by myself? Is there any API available for this purpose?

        • 1. Re: How to check if entity bean is changed
          epbernard

          There is no public API but through a hibernate interceptor you can achieve this

          • 2. Re: How to check if entity bean is changed
            atodorov

            Do you mean something like this:

            @Stateless
            public class BlaBlaBean implements BlaBla {
             ....
             public void editMyEntity(Doctor d) {
             // calling entityManager.merge(d) here
             }
            
             @AroundInvoke
             public Object mySessionBeanInterceptor(InvocationContext ctx) throws Exception {
             Doctor newDoctor = (Doctor) ctx.getParameters()[0];
             Doctor persistedDoctor = entityManager.find(Doctor, newDoctor.getId());
            
             // comparing the properties values of newDoctor and
             // persistedDoctor manually (or via reflection),
             // save the differences somewhere etc...
            
             return ctx.proceed();
             }
            }
            



            • 3. Re: How to check if entity bean is changed
              epbernard

              no a hibernate interceptor org.hibernate.Interceptor, check the Hibernate reference guide for more info.