I use Spring Data, Hibernate and Microsoft SQL Server. I have 2 entities: Role
and Privilege
. One role has many privileges. Privileges have VALID_TO
column.
I want every role to have only privileges that are still valid (i.e., VALID_TO <= GETDATE()
).
The simplest way I found to implement this is by annotating the Privilege
entity with the Hibernate @Where
annotation, like this:
// ...
@Where(clause = "VALID_TO <= GETDATE()")
class Privilege {
// ...
}
But the disadvantage of this approach is that it uses Transact-SQL; it will cause additional rework in case of migration to another database. Also, this approach makes the code dependent on Hibernate annotations.
Is there a way to filter out the privileges using pure Spring Data?