Constraint.NO_CONSTRAINT has no effect on @ForeignKey for a @JoinTable or @JoinColumn in @JoinTable
Description
Activity
Show:
Details
Details
Assignee
Unassigned
UnassignedReporter
vu.do
vu.doLabels
Components
Affects versions
Priority
Created July 6, 2020 at 8:42 PM
Updated July 6, 2020 at 8:55 PM
It is impossible to set Constraint.NO_CONSTRAINT for a @JoinColumn in @JoinTable. It will generate a FK no matter what. This occur to all version of Hibernate
Error: Foreign key (FK3io8xbemymxv4bm5ccmh2ba8a:audience_sharing [audience_group_id,provider_id])) must have same number of columns as the referenced primary key (audience_group [audience_group_id])
I have tried all workaround but none works. The work arounds which applied the example below:
@JoinColumn(name = "provider_id", referencedColumnName = "provider_id", foreignKey = @ForeignKey(value = Constraint.NO_CONSTRAINT)
@JoinColumn(name = "provider_id", referencedColumnName = "provider_id", foreignKey = @ForeignKey(name = “none”, value = Constraint.NO_CONSTRAINT)
@JoinTable( foreignKey = @ForeignKey(value = Constraint.NO_CONSTRAINT) )
Example:
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) @JoinTable( name = "sharing", joinColumns = { @JoinColumn(name = "audience_group_id", referencedColumnName = "audience_group_id"), @JoinColumn(name = "provider_id", referencedColumnName = "provider_id", foreignKey = @ForeignKey(value = Constraint.NO_CONSTRAINT)), }, inverseJoinColumns = @JoinColumn(name = "product_id") ) @JsonManagedReference private Set<Product> products = new HashSet<>(0);