caching relations mapped by other entity

261 views Asked by At

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.

0

There are 0 answers