@ManyToMany throws a ConstraintViolationException when removing entity from the mapped-by (inverse) side

Description

If we have the following many-to-many association:

Removing the Post works just fine:

However, removing the Address throws a ConstraintViolationException:

and this is the stacktrace:

Environment

None

Activity

Show:
Vlad Mihalcea
January 23, 2018, 6:57 AM

Replicating test case can be found in hibernate-core:

org.hibernate.test.manytomany.ManyToManyBidirectionalTest

Khalil Bouzekri
November 23, 2018, 10:28 AM

I have got the same issue.

Is there any quick (and not too dirty) workaround regarding this issue?

Giorgio Vinci
May 28, 2019, 2:00 PM

No update on this issue? I second @khalil question, what's the workaround?

Vlad Mihalcea
May 28, 2019, 2:17 PM

Try using a DDL ON_DELETE cascade on the FK. This way, you'll never get that ConstraintViolationException.

Giorgio Vinci
May 29, 2019, 7:32 AM

Thanks, going through again on your blog post here: https://vladmihalcea.com/a-beginners-guide-to-jpa-and-hibernate-cascade-types/ and just realized that indeed I might be too aggressive deleting.

Assignee

Unassigned

Reporter

Vlad Mihalcea

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure