I have two entities that are related to each other by a one-to-one relationship. Both entities have the same ID by @MapsId. When I try to delete a child entity, I get a ConstraintViolationException exception because the parent entity is deleted before the child. I think this is due to changes in OneToOneSecondPass#doSecondPass. Setting ForeignKeyDirection has changed and now is TO_PARENT except FROM_PARENT.
{code:java}@Entity(name = "ResourceIdentity") @Table(name = "RESOURCE_IDENTITY") @Access(AccessType.FIELD) public static class ResourceIdentity { Long id;
@Id @Column(name = "ID") @Access(AccessType.PROPERTY) @GeneratedValue(strategy = GenerationType.SEQUENCE) public Long getId() { return id; }
public void setId(Long id) { this.id = id; } }
@Entity(name = "ResourceUnit") @Table(name = "RESOURCE_UNIT") @Access(AccessType.FIELD) public static class ResourceUnit {
Long id;
@Id @Column(name = "ID") @Access(AccessType.PROPERTY) @GeneratedValue(strategy = GenerationType.SEQUENCE) public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "id") @MapsId private ResourceIdentity identity;
public ResourceIdentity getIdentity() { return identity; }
public void setIdentity(ResourceIdentity identity) { this.identity = identity; } }{code}
testcase: [https://github.com/argustelecom/hibernate-orm/commit/b232f016d3c19d714bb37d316141dcb536de60f3|https://github.com/argustelecom/hibernate-orm/commit/b232f016d3c19d714bb37d316141dcb536de60f3|smart-link]
I have solution, but I just wanna ask is it correct or not. [https://github.com/argustelecom/hibernate-orm/commit/de9ce74551df49c32fe64c70bea99d29f01c12da|https://github.com/argustelecom/hibernate-orm/commit/de9ce74551df49c32fe64c70bea99d29f01c12da|smart-link] |
|