Before hibernate 6 we had mapped fields like this(or without insertable/updatable=false). The reason for it was to avoid N+1 problem, and as far as I remember this was actually working. The field was lazily initilized without N+1 problem.
//…
public class EntityA {
//…
@BatchSize(size = 100)
@ManyToOne(fetch = FetchType.LAZY)
@JdbcTypeCode(Types.VARCHAR)
@JoinColumn(name = "limit_id", insertable = false, updatable = false)
private EntityB entityB;
}
the other side looked like:
//…
public class EntityB {
//…
@Setter(AccessLevel.NONE)
@OneToMany(mappedBy = "entityB")
@BatchSize(size = 100)
private List<EntityA> entityAs;
}
But with hibernate 6 I’m getting:
Caused by: org.hibernate.AnnotationException: Property 'entityB' may not be annotated '@BatchSize'
was something changed? How things should be now, if we don’t want to go back to N+1 problem? Yes, I saw some comments, that this really never was supported, but I also saw comments, that it actually was on lazy loaded fields, and my memory is telling me that this was the case. Can someone advise?