Here is what happened:
Incident
defined a@ManyToOne
to an entityProject
Project
incorrectly defined a@ManyToMany
back to the entityIncident
(should have been a@OneToMany
)As a result Hibernate generated the awkward following constraint:
CONSTRAINT fk909a8f241708a1e FOREIGN KEY (uuid) REFERENCES incident (uuid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION
Incident
inheritsSomeBaseClass
which has@Inheritance(strategy = InheritanceType.JOINED)
As a result Hibernate generated the following constraint:
CONSTRAINT fk909a8f2ddd08e84 FOREIGN KEY (uuid) REFERENCES somebaseclass (uuid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION
As a result of HHH-8217 (Make generated constraint names short and non-random) in Hibernate 4.2.2 the above two constraint definitions suddenly got the same name (Hibernate did only consider the entity and the columns of the foreign key constraint, not the target entity of the foreign key; note how
generateName
only takes oneTable
as a parameter)- And there was the corresponding clash:
Constraint ... already exists
Changing the @ManyToMany
to @OneToMany
fixes this entirely.
By the way, the offending field definition (the one with the @ManyToMany
) also previously caused me problems with Hibernate Envers' @Audited
, the reason of which I never understood, and that got resolved now as well. It's a good day. (Not sure if @Audited
means much for a mapped field, but at least I can have @Audited
on the class without needing to deal with this field.)