At the moment I'm updating some @org.hibernate.annotations.Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
annotations with the JPA equivalent @javax.persistence.Cacheable
. This works well on @Entity
level, but cannot be done for @OneToMany
relationships.
My question is similar to Can we use JPA2 annotations to cache associations? but I think it's appropriate to ask again after 10 years while it was self-answered with "there is no replacement for the hibernate annotation" such a long time ago.
Now my question: Are there replacements in the javax.persistence
or jakarta.persistence
packages for @org.hibernate.annotations.Cache
?
@Entity
@javax.persistence.Cacheable
public class Tutor
{
@org.hibernate.annotations.Cache <---- REPLACE this with JPA
@OneToMany(mappedBy="tutor")
private Set<Student> students;
}
@Entity
@javax.persistence.Cacheable
public class Student
{
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="TUTOR_FK")
private Tutor tutor;
}
BTW: If someone is reading this question in the context of performance improvements, I recommend these articles