I am trying to disable the foreign key constraint being generated on my bidirectional association. I have managed to do this for all my unidirectional associations, but for some reason it is not working here.
I do know about the bug with ContraintMode.NO_CONSTRAINT that was recently fixed in Hibernate 5.x, and I am running the latest Hibernate 5.2.6.
My annotations presently look like this:
class Parent {
@OneToMany(mappedBy="parent", cascade=CascadeType.ALL, orphanRemoval=true)
@OrderColumn(name="childIndex")
public List<Child> getChildren() {
return children;
}
}
class Child {
@ManyToOne(optional=false)
@JoinColumn(name="parent", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
public Parent getParent() {
return parent;
}
}
But despite NO_CONSTRAINT, Hibernate is still creating the foreign key constraint on child.parent -> parent.id.
Is there something additional I need to do to suppress the foreign key for the bidirectional case?
Thanks!
javax.persistence.ForeignKey
is what's used in the OP. It does not work, and it cannot be applied to a field. – Tyishatyke