[JIRA] (HHH-16997) Embedded components in HibernateProxy are not initilized when entity has reference to another entity of the same type
by Bartlomiej Niemiec (JIRA)
Bartlomiej Niemiec ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cdd0b2... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiY2RhMmVkNmNl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16997?atlOrigin=eyJpIjoiY2RhMm... ) HHH-16997 ( https://hibernate.atlassian.net/browse/HHH-16997?atlOrigin=eyJpIjoiY2RhMm... ) Embedded components in HibernateProxy are not initilized when entity has reference to another entity of the same type ( https://hibernate.atlassian.net/browse/HHH-16997?atlOrigin=eyJpIjoiY2RhMm... )
Issue Type: Bug Affects Versions: 6.3.0.CR1, 6.2.7 Assignee: Unassigned Components: hibernate-core Created: 26/Jul/2023 04:52 AM Priority: Major Reporter: Bartlomiej Niemiec ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cdd0b2... )
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;
// rest of the code
@Embeddable
public class ComponentA implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cmpa_a_id" , referencedColumnName = "id" , insertable = false , updatable = false )
private EntityA entityA;
// rest ot the code
@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;
// rest of the code
@Entity
@Table(schema = "test" , name = "t_entity_b" )
public class EntityB implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "id" , referencedColumnName = "id" )
private EntityA entityA;
// rest ot the code
@Entity
@Table(schema = "test" , name = "t_entity_c" )
public class EntityC implements Serializable {
@Id
private Integer id;
// rest of the code
@Entity
@Table(schema = "test" , name = "t_entity_d" )
public class EntityD implements Serializable {
@Id
private Integer id;
// rest ot the code
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
( https://hibernate.atlassian.net/browse/HHH-16997#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16997#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:62cfdef )
2 years, 4 months