Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) *commented* on HHH-16834 (
https://hibernate.atlassian.net/browse/HHH-16834?atlOrigin=eyJpIjoiNzU2ZW...
)
Re: Impossible to remove an entity that contains OneToMany relation (CascadeType_ALL)
while using @EmbeddedId for the entity associated (
https://hibernate.atlassian.net/browse/HHH-16834?atlOrigin=eyJpIjoiNzU2ZW...
)
If the @JoinColumn is part of an @EmbeddedId , and as such is non-nullable, you can’t
expect to have correct results when updating the association. Since the information about
which EntityB is associated with an EntityA is stored in that column, Hibernate needs to
be able to set it to null to signify that no associated entity is present.
The correct way to map this, if you really want to keep the foreign key as part of the
composite EntityB id, would be something like this:
@Embeddable
static class EmbeddedKey implements Serializable {
@ManyToOne
@JoinColumn( name = "entityaid" )
private EntityA entityA;
@Column( name = "type" , updatable = false )
private Integer type;
}
And then using mappedBy="id.entityA" on the EntityA association side.
A simpler way forward would be decoupling the join column from EntityB ’s identifier.
(
https://hibernate.atlassian.net/browse/HHH-16834#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16834#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100230- sha1:acc9c6f )