JPA association without foreign key

后端 未结 3 619
孤城傲影
孤城傲影 2020-12-28 11:43

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

相关标签:
3条回答
  • 2020-12-28 11:50

    Add name="none" in javax.persistence.ForeignKey,

    this worked for me.

    foreignKey = @javax.persistence.ForeignKey(name="none",value = ConstraintMode.NO_CONSTRAINT)
    
    0 讨论(0)
  • 2020-12-28 11:59

    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.

    0 讨论(0)
  • 2020-12-28 12:10

    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!!!

    0 讨论(0)
提交回复
热议问题