Hibernate: check which entity's fields are modified

后端 未结 3 2162
予麋鹿
予麋鹿 2020-12-29 04:59

What I have:

I\'ve Hibernate entity, which contains many non-transient fields, including collections. User can update each field separately

相关标签:
3条回答
  • 2020-12-29 05:38

    What you can do is make a Hibernate Interceptor that would act like a trigger in the events like create, modify and update. http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/events.html so that any point before the given entity is about to be modified and persisted, 1.You can check whether the user has the access (you can get username from session or database) to modify the particular field and accordingly you can grant the access to save or update. 2.You can notify the other user about only when the entity is modified.

    By this way you can make a new session-scope Interceptor in spring's implementation ofHibernate 4 Session session = s.withOptions().interceptor(new YourInterceptor().openSession();

    0 讨论(0)
  • 2020-12-29 05:46

    If what you want is to be able to check which fields have been modified, it may be worth taking a look at Hibernate Envers, which works as an auditing tool that creates a separate table containing the changes that were made to your business logic table.

    http://www.jboss.org/envers

    I started using it for some internal auditing and it's really simple and works like a charm.

    Here's a quick tutorial:

    https://thenewcircle.com/s/post/115/easy_auditing_versioning_for_your_hibernate_entities_with_envers

    0 讨论(0)
  • 2020-12-29 05:54

    I think Hibernate interceptors can be used http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/events.html you can compare old and new values of the entity fields.

    0 讨论(0)
提交回复
热议问题