tags:

views:

36

answers:

1

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 field value in one table.

A: 

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

References

Pascal Thivent
Please see the EDITED part. Will filter still be appropriate to complicated sql? does it use cache? when I use Listener, each object holds collection of objects that are cached and it may save db time
Odelya
I am afraid that using Filter will invoke cache for EACH sql being generated, instead of ability to use cached collection on objects and get cached information..
Odelya
@Odelya: I don't know the exact behavior when used in conjunction with query caching, this would require some testing. Actually, I think that both solutions would require some testing.
Pascal Thivent
But how is it possible to implement filter if the value is in a many to many table and not in the table itself?
Odelya