0

I'm trying to cache some of my entities that only get changed when the server is down. Here is an example:

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class Season {

    @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
    @OneToOne(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
    @JoinColumn(name="next_id")
    protected Season next;

}

This works well.

But when I add the reverse relation, then I see hibernate querying the database for that relation.

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class Season {

    @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
    @OneToOne(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
    @JoinColumn(name="next_id")
    protected Season next;

    @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
    @OneToOne(mappedBy="next", fetch=FetchType.EAGER)
    protected Season previous;
}

it makes no difference if I declare it EAGER or LAZY.

How can I configure my Cache / Entity / Relations , so the Season Entity is cached completely including the "next" AND "previous" relations?

And if there was a way to do that with JPA's @Cacheable, I'd like that even more.

EasterBunnyBugSmasher
  • 1,507
  • 2
  • 15
  • 34
  • 1
    Here is a [duplicate](https://stackoverflow.com/questions/56233710/hibernate-caching-not-working-for-inverse-side-of-one-to-one-relationship) of your question, and the [ticket](https://hibernate.atlassian.net/browse/HHH-13422) is still pending – crizzis Oct 10 '20 at 14:01
  • thanks! Now I can stop searching for my mistakes. – EasterBunnyBugSmasher Oct 11 '20 at 09:31

0 Answers0