With the model below, and with bytecode enhancement enabled, calling EntityB#getMyAssociation will always yield a null value, even if the association is supposedly non-`null`.
I’ll send a PR with a reproducer.
@Entity(name = "entitya")
public static class EntityA {
@Id
private Integer id;
@Column(unique = true)
private String myUniqueKey;
protected EntityA() {
}
public EntityA(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMyUniqueKey() {
return myUniqueKey;
}
public void setMyUniqueKey(String myUniqueKey) {
this.myUniqueKey = myUniqueKey;
}
}
@Entity(name = "entityb")
public static class EntityB {
@Id
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "myForeignKey", referencedColumnName = "myUniqueKey")
private EntityA myAssociation;
protected EntityB() {
}
public EntityB(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public EntityA getMyAssociation() {
return myAssociation;
}
public void setMyAssociation(EntityA myAssociation) {
this.myAssociation = myAssociation;
}
}