We are in the midst of a migration from spring 5 → 6 and hibernate upgrade as part of it. All is going well except an issue with our Hibernate L2 Cache. We are using Redisson and spring boot 3.4 with corresponding hibernate 6.
We have two objects lets call them
A
AConfig
In A we have class annotated with
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "A_1725466322")
with object inside
@OneToOne(fetch = FetchType.EAGER, mappedBy = "a")
@Fetch(FetchMode.SELECT)
@Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE })
public AConfig getAConfig() {
return a;
}
And AConfig is class annotated
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "AConfig_1741191503")
with inner object
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "a_id")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
public A getA() {
return a;
}
In Hibernate 5, this all worked and we wouldn’t see subsequent requests to the database for AConfig.
In Hibernate 6.6, everytime we pull the A from Hibernate we see a query to the DB for AConfig.
Can someone explain to me why?
If i change the object to a Set and create a single transient getAConfig on A and change from OneToOne to OneToMany/ManyToOne it caches properly…but thats not ideal.