Hibernate: check which entity's fields are modified

后端 未结 3 2182
予麋鹿
予麋鹿 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();

提交回复
热议问题