I have many-to-many relationship between User
and Role
. There is a third table called UserRole
mapped as a join-table.
In JPA I can cache User
and Role
using @Cachable
; however when I try to fetch the Role
s associated to the User
which is defined EAGER
, a database query is executed to fetch the values from the join-table.
How can I cache the join-table between User
and Role
?
Decide your caching concurrency strategy based on here and use @Cache on top of your association:
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "user_roles")
Make sure to mark the both entities (in this case User and Role) with @Cacheable too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With