mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-25 21:04:51 +00:00
HHH-16209 Reproducer for mixup during loading of identically-named association in entity root and embeddable
This commit is contained in:
parent
6d5c6e002d
commit
5e82db1caa
@ -24,30 +24,32 @@
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
@TestForIssue(jiraKey = "TODO")
|
@TestForIssue(jiraKey = "HHH-16209")
|
||||||
public class EmbeddableWithIdenticallyNamedAssociationTest {
|
public class EmbeddableWithIdenticallyNamedAssociationTest {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public void setUp(SessionFactoryScope scope) {
|
public void setUp(SessionFactoryScope scope) {
|
||||||
EntityA a1 = new EntityA();
|
EntityA a1 = new EntityA();
|
||||||
a1.setId( 1 );
|
a1.setId( 1 );
|
||||||
|
|
||||||
EntityB b1 = new EntityB();
|
EntityB b1 = new EntityB();
|
||||||
b1.setId( 1 );
|
b1.setId( 1 );
|
||||||
b1.setIdenticallyNamedAssociationFromB( a1 );
|
b1.setEntityA( a1 );
|
||||||
a1.setIdenticallyNamedAssociationFromA( b1 );
|
a1.setEntityB( b1 );
|
||||||
|
|
||||||
EntityA a2 = new EntityA();
|
EntityA a2 = new EntityA();
|
||||||
a2.setId( 2 );
|
a2.setId( 2 );
|
||||||
EntityB b2 = new EntityB();
|
EntityB b2 = new EntityB();
|
||||||
b2.setId( 2 );
|
b2.setId( 2 );
|
||||||
b2.setIdenticallyNamedAssociationFromB( a2 );
|
b2.setEntityA( a2 );
|
||||||
a2.setIdenticallyNamedAssociationFromA( b2 );
|
a2.setEntityB( b2 );
|
||||||
|
|
||||||
EmbeddableB embeddableB = new EmbeddableB();
|
EmbeddableB embeddableB = new EmbeddableB();
|
||||||
embeddableB.setIdenticallyNamedAssociationFromB( a2 );
|
embeddableB.setEntityA( a2 );
|
||||||
b1.setEmbeddableB( embeddableB );
|
b1.setEmbeddableB( embeddableB );
|
||||||
|
|
||||||
EmbeddableA embeddableA = new EmbeddableA();
|
EmbeddableA embeddableA = new EmbeddableA();
|
||||||
embeddableA.setIdenticallyNamedAssociationFromA( b1 );
|
embeddableA.setEntityB( b1 );
|
||||||
a2.setEmbeddableA( embeddableA );
|
a2.setEmbeddableA( embeddableA );
|
||||||
|
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
@ -66,16 +68,16 @@ private void assertEntityContent(EntityA a1, EntityA a2, EntityB b1, EntityB b2)
|
|||||||
assertThat( b1 ).isNotNull();
|
assertThat( b1 ).isNotNull();
|
||||||
assertThat( b2 ).isNotNull();
|
assertThat( b2 ).isNotNull();
|
||||||
|
|
||||||
assertThat( b1.getIdenticallyNamedAssociationFromB() ).isEqualTo( a1 );
|
assertThat( b1.getEntityA() ).isEqualTo( a1 );
|
||||||
assertThat( a1.getIdenticallyNamedAssociationFromA() ).isEqualTo( b1 );
|
assertThat( a1.getEntityB() ).isEqualTo( b1 );
|
||||||
|
|
||||||
assertThat( b2.getIdenticallyNamedAssociationFromB() ).isEqualTo( a2 );
|
assertThat( b2.getEntityA() ).isEqualTo( a2 );
|
||||||
assertThat( a2.getIdenticallyNamedAssociationFromA() ).isEqualTo( b2 );
|
assertThat( a2.getEntityB() ).isEqualTo( b2 );
|
||||||
|
|
||||||
assertThat( b1.getEmbeddableB() ).isNotNull();
|
assertThat( b1.getEmbeddableB() ).isNotNull();
|
||||||
assertThat( b1.getEmbeddableB().getIdenticallyNamedAssociationFromB() ).isEqualTo( a2 );
|
assertThat( b1.getEmbeddableB().getEntityA() ).isEqualTo( a2 );
|
||||||
assertThat( a2.getEmbeddableA() ).isNotNull();
|
assertThat( a2.getEmbeddableA() ).isNotNull();
|
||||||
assertThat( a2.getEmbeddableA().getIdenticallyNamedAssociationFromA() ).isEqualTo( b1 );
|
assertThat( a2.getEmbeddableA().getEntityB() ).isEqualTo( b1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,8 +99,8 @@ public static class EntityA {
|
|||||||
@Id
|
@Id
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@OneToOne(mappedBy = "identicallyNamedAssociationFromB")
|
@OneToOne(mappedBy = "entityA")
|
||||||
private EntityB identicallyNamedAssociationFromA;
|
private EntityB entityB;
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
private EmbeddableA embeddableA;
|
private EmbeddableA embeddableA;
|
||||||
@ -107,7 +109,7 @@ public static class EntityA {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "EntityB{" +
|
return "EntityB{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", identicallyNamedAssociationFromA=" + identicallyNamedAssociationFromA.getId() +
|
", entityB =" + entityB.getId() +
|
||||||
", embeddableA=" + embeddableA +
|
", embeddableA=" + embeddableA +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
@ -120,12 +122,12 @@ public void setId(Integer id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityB getIdenticallyNamedAssociationFromA() {
|
public EntityB getEntityB() {
|
||||||
return identicallyNamedAssociationFromA;
|
return entityB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdenticallyNamedAssociationFromA(EntityB identicallyNamedAssociationFromA) {
|
public void setEntityB(EntityB entityB) {
|
||||||
this.identicallyNamedAssociationFromA = identicallyNamedAssociationFromA;
|
this.entityB = entityB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmbeddableA getEmbeddableA() {
|
public EmbeddableA getEmbeddableA() {
|
||||||
@ -139,22 +141,22 @@ public void setEmbeddableA(EmbeddableA embeddableA) {
|
|||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public static class EmbeddableA {
|
public static class EmbeddableA {
|
||||||
@OneToOne(mappedBy = "embeddableB.identicallyNamedAssociationFromB")
|
@OneToOne(mappedBy = "embeddableB.entityA")
|
||||||
private EntityB identicallyNamedAssociationFromA;
|
private EntityB entityB;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EmbeddableA{" +
|
return "EmbeddableA{" +
|
||||||
", identicallyNamedAssociationFromA=" + identicallyNamedAssociationFromA.getId() +
|
", entityB=" + entityB.getId() +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityB getIdenticallyNamedAssociationFromA() {
|
public EntityB getEntityB() {
|
||||||
return identicallyNamedAssociationFromA;
|
return entityB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdenticallyNamedAssociationFromA(EntityB a) {
|
public void setEntityB(EntityB a) {
|
||||||
this.identicallyNamedAssociationFromA = a;
|
this.entityB = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ public static class EntityB {
|
|||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "entityA_id")
|
@JoinColumn(name = "entityA_id")
|
||||||
private EntityA identicallyNamedAssociationFromB;
|
private EntityA entityA;
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
private EmbeddableB embeddableB;
|
private EmbeddableB embeddableB;
|
||||||
@ -174,7 +176,7 @@ public static class EntityB {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "EntityB{" +
|
return "EntityB{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", identicallyNamedAssociationFromB=" + identicallyNamedAssociationFromB.getId() +
|
", entityA=" + entityA.getId() +
|
||||||
", embeddableB=" + embeddableB +
|
", embeddableB=" + embeddableB +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
@ -187,12 +189,12 @@ public void setId(Integer id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityA getIdenticallyNamedAssociationFromB() {
|
public EntityA getEntityA() {
|
||||||
return identicallyNamedAssociationFromB;
|
return entityA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdenticallyNamedAssociationFromB(EntityA a) {
|
public void setEntityA(EntityA a) {
|
||||||
this.identicallyNamedAssociationFromB = a;
|
this.entityA = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmbeddableB getEmbeddableB() {
|
public EmbeddableB getEmbeddableB() {
|
||||||
@ -208,21 +210,21 @@ public void setEmbeddableB(EmbeddableB embeddableB) {
|
|||||||
public static class EmbeddableB {
|
public static class EmbeddableB {
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "emb_entityA_id")
|
@JoinColumn(name = "emb_entityA_id")
|
||||||
private EntityA identicallyNamedAssociationFromB;
|
private EntityA entityA;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EmbeddableB{" +
|
return "EmbeddableB{" +
|
||||||
", identicallyNamedAssociationFromB=" + identicallyNamedAssociationFromB.getId() +
|
", entityA=" + entityA.getId() +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityA getIdenticallyNamedAssociationFromB() {
|
public EntityA getEntityA() {
|
||||||
return identicallyNamedAssociationFromB;
|
return entityA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdenticallyNamedAssociationFromB(EntityA a) {
|
public void setEntityA(EntityA a) {
|
||||||
this.identicallyNamedAssociationFromB = a;
|
this.entityA = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user