[hibernate-issues] [JIRA] (HHH-14099) Constraint.NO_CONSTRAINT has no effect on @ForeignKey for a @JoinTable or @JoinColumn in @JoinTable

vu.do (JIRA) jira at hibernate.atlassian.net
Mon Jul 6 16:54:25 EDT 2020


vu.do ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e0db4bb4006ea0ea327f77b ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14099?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 ) HHH-14099 ( https://hibernate.atlassian.net/browse/HHH-14099?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 ) Constraint.NO_CONSTRAINT has no effect on @ForeignKey for a @JoinTable or @JoinColumn in @JoinTable ( https://hibernate.atlassian.net/browse/HHH-14099?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 )

Change By: vu.do ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e0db4bb4006ea0ea327f77b )

It is impossible to set Constraint.NO_CONSTRAINT for a @JoinColumn in @JoinTable. It will generate a FK no matter what.

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:

{code:java}@JoinColumn(name = "provider_id", referencedColumnName = "provider_id", foreignKey = @ForeignKey(value = Constraint.NO_CONSTRAINT){code}

{noformat}@JoinColumn(name = "provider_id", referencedColumnName = "provider_id", foreignKey = @ForeignKey(name = “none”, value = Constraint.NO_CONSTRAINT){noformat}

{noformat}@JoinTable(
foreignKey = @ForeignKey(value = Constraint.NO_CONSTRAINT)
){noformat}

Example:

{code:java}@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);{code}

( https://hibernate.atlassian.net/browse/HHH-14099#add-comment?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14099#add-comment?atlOrigin=eyJpIjoiNDg4ZDg3NGM2OTQ3NDdhMGFlOWU1NzZiMGM3ZTQzNmUiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100131- sha1:aac02e2 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200706/8359970b/attachment.html 


More information about the hibernate-issues mailing list