I have the following mappings:
@Entity
@Table(schema = "test", name = "t_entity_a")
public class EntityA implements Serializable {
@Id
private Integer id;
@Embedded
private ComponentA componentA;
@Embedded
private ComponentB componentB;
@OneToOne(mappedBy = "entityA")
private EntityB entityB;
@Embeddable
public class ComponentA implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cmpa_a_id", referencedColumnName = "id", insertable = false, updatable = false)
private EntityA entityA;
@Embeddable
public class ComponentB implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cmpb_c_id", referencedColumnName = "id")
private EntityC entityC;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cmpb_d_id", referencedColumnName = "id")
private EntityD entityD;
@Entity
@Table(schema = "test", name = "t_entity_b")
public class EntityB implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "id", referencedColumnName = "id")
private EntityA entityA;
@Entity
@Table(schema = "test", name = "t_entity_c")
public class EntityC implements Serializable {
@Id
private Integer id;
@Entity
@Table(schema = "test", name = "t_entity_d")
public class EntityD implements Serializable {
@Id
private Integer id;
Let’s create in database record for entity A(let’s assume id = 1) with existing relationships to entity B and entity D through component B. Next we create next row for entitiy A (id = 2) with relationship to first entity A through component A. When loading both A entities in single query, if set order to load entity with id = 2 before entity with id = 1, then that second entity (id = 1) will be loaded as proxy (because of the lazy relationships from first loaded entity). But the problem is that component B in that proxy will no get initialized when accessing the data. Names of classes in this example are generic, but this is narrowed and simplified mapping from production code. I think this is some kind of very specific corner case, because removing any relationship from this entities or components make this problem disappear. Last version in which this example worked is 6.2.1.Final |