Have a problem with initialization lazy field in entity. In spring 2.5 everything works but after updating to 2.6 faced issue. I have 2 entities user and his avatar. When I fetch user via repository findById the avatar field is initialized as new object with null fields. There are entities
@Entity
public class User {
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "avatar_id", referencedColumnName = "id")
@LazyToOne(LazyToOneOption.NO_PROXY)
@LazyGroup("user.avatar")
private Image avatar;
@Column(name = "avatar_id", insertable = false, updatable = false)
private String avatarId;
public Image getAvatar() {
if (interceptor != null) {
this.avatar = (Image) interceptor.readObject(this, "avatar", avatar);
}
return avatar;
}
public void setAvatar(Image avatar) {
if (interceptor != null) {
this.avatar = (Image) interceptor.writeObject(this, "avatar", this.avatar, avatar);
} else {
this.avatar = avatar;
}
}
}
@Entity
public class Image {
private String fileName;
@JsonIgnore
@Lob
@Column(nullable = false, columnDefinition="MEDIUMBLOB")
private byte[] image;
}
To get and save avatar to User I use hibernate interceptor and setAvatar/getAvatar method accordingly. user.setAvatar(image); user.getAvatar();
When I save avatar via REST API methods setAvatar/getAvatar works as expected, create new entity avatar and add ID into user.
But when I call REST API to get avatar user.getAvatar() returns Image(fileName=null, image=null) and after calling interceptor.readObject(this, "avatar", avatar) it return the same.
Interceptor class is LazyAttributeLoadingInterceptor.