Fails on ORM 6.2, but not on 6.1. I’ll add a reproducer in the comments. With a model like this (cannot be simpler, unfortunately):
@Entity(name = "entitya")
public static class EntityA {
@Id
private Integer id;
@OneToOne
private EntityA selfAssociation;
@OneToOne(mappedBy = "selfAssociation")
private EntityA mappedSelfAssociation;
@OneToOne(mappedBy = "association1", fetch = FetchType.LAZY)
private EntityB mappedAssociation1;
@OneToOne(mappedBy = "association2", fetch = FetchType.LAZY)
private EntityB mappedAssociation2;
protected EntityA() {
}
public EntityA(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public EntityA getSelfAssociation() {
return selfAssociation;
}
public void setSelfAssociation(EntityA selfAssociation) {
this.selfAssociation = selfAssociation;
}
public EntityA getMappedSelfAssociation() {
return mappedSelfAssociation;
}
public void setMappedSelfAssociation(EntityA mappedSelfAssociation) {
this.mappedSelfAssociation = mappedSelfAssociation;
}
public EntityB getMappedAssociation1() {
return mappedAssociation1;
}
public void setMappedAssociation1(EntityB mappedAssociation1) {
this.mappedAssociation1 = mappedAssociation1;
}
public EntityB getMappedAssociation2() {
return mappedAssociation2;
}
public void setMappedAssociation2(EntityB mappedAssociation2) {
this.mappedAssociation2 = mappedAssociation2;
}
}
@Entity(name = "entityb")
public static class EntityB {
@Id
private Integer id;
@OneToOne
private EntityA association1;
@OneToOne
private EntityA association2;
protected EntityB() {
}
public EntityB(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public EntityA getAssociation1() {
return association1;
}
public void setAssociation1(EntityA association1) {
this.association1 = association1;
}
public EntityA getAssociation2() {
return association2;
}
public void setAssociation2(EntityA association2) {
this.association2 = association2;
}
}
This will fail:
inTransaction( s -> {
EntityA entityA = s.get( EntityA.class, 1 );
EntityB entityB = new EntityB( 2 );
entityA.setMappedAssociation1( entityB );
entityB.setAssociation1( entityA );
s.persist( entityB );
} );
With the following exception:
|