| Creating issue for discussion here at https://discourse.hibernate.org/t/hibernate-onetoone-with-mapsid-does-not-map-the-same-id-with-the-parent-entity/2093/9 Summary: A child entity is mapped using @OneToOne with @MapsId to its parent entity. For eg,
class Parent {
}
class Child {
@OneToOne
@MapsId
private Parent parent;
}
The assumption is that child will refer to its correct parent in any case. However, following code will break this assumption.
Parent p = new Parent(); em.save(p);
em.flush();
Child c = em.find(Child.class, 1L); c.setParent(p); Child result = em.merge(c);
result.getParent();
This way it will continue to use new parent until the end of transaction. @OneToOne with @MapsId should always resolves to correct association value. Sample test cases which show the issue. https://github.com/pmverma/hibernate-mapsid-test https://github.com/vladmihalcea/high-performance-java-persistence/pull/36 |