I need to restrict the resulting rows from each table/object depending on my security rules per logged user.
I thought to use implement PreLoadEventListener
.
Regarding performance - how expensive is it to use onPreLoad for each entity? does Hibernate assign the relevant listener via Reflection? Is it done once per Hibernate session or each find will it invoke the reflection to find the appropiate listener?
EDITED
The security condition is complicated. It's based on 5 tables, since I have to check the user group to check that one of the group's role has access to the row in the database (labeling security). It's a condition on a fiel开发者_开发问答d value in one table.
I need to restrict the resulting rows from each table/object depending on my security rules per logged user.
Did you consider using Filters instead of a listener? This seems more appropriate to me.
Related question
- Are Hibernate filters only applied after the data has been loaded from db?
References
- Hibernate Core Reference Guide
- Chapter 17. Filtering data
精彩评论