Coming from this Discourse discussion, the problem is when using second level caching along with @BatchSize, because cache entries are put into the cache, before the BatchEntitySelectFetchInitializer for an association set the value on the owning entity, so the cache entry contains null for the association which is wrong. Reading from the cache later leads to materializing wrong data.
@Entity
@BatchSize(10)
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Parent {
@Id
Long id;
@ManyToOne
Child c;
}
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Child {
@Id
Long id;
String name;
}
|