Is it possible to set up a ManyToOne association without JPA creating a foreign key in the database?
The tables are owned by another system and are populated asynchr
Add name="none"
in javax.persistence.ForeignKey
,
this worked for me.
foreignKey = @javax.persistence.ForeignKey(name="none",value = ConstraintMode.NO_CONSTRAINT)
The fact that ConstraintMode.NO_CONSTRAINT is ignored looks like a bug in Hibernate 4 due to be fixed in 5.
https://hibernate.atlassian.net/browse/HHH-8805
The comments on that and indeed this post here:
Multiple relationships with single mapping table without generating foreign keys by Hibernate
suggest adding the deprecated (hibernate rather than JPA) annotation
@ForeignKey( name = "none" )
to the relationship should work.
In Hibernate 4.3.X annotation field with @org.hibernate.annotations.ForeignKey( name = "none") worked for me.
But be carefull: in case of bidirectional relationships, you have to annotate two fields by mentionad annotation!!!