How to name the foreign key constraint of ManyToOne references since JPA 2.1?

后端 未结 3 2032
悲&欢浪女
悲&欢浪女 2021-02-03 23:37

@org.hibernate.annotations.ForeignKey has been deprecated, but I cannot find any examples how the JPA 2.1 equivalent would have to look like?

@ManyT         


        
相关标签:
3条回答
  • You're right, I misread the documentation. It can be defined as a part of @JoinColumn annotation.

    It should look like that:

    @JoinColumn(foreignKey = @ForeignKey(name = "FK_USER"))
    
    0 讨论(0)
  • 2021-02-04 00:23

    Do you insert @JoinColumn(foreignKey = @ForeignKey(name = "FK_USER")) direct to mapped to entity example:

    @ManyToOne
    @JoinColumn(foreignKey = @ForeignKey(name = "FK_USER"))
    private User user;
    
    0 讨论(0)
  • 2021-02-04 00:31

    As the documentation indicates, this annotation can't be applied to anything:

    @Target(value={})

    It can thus only be used as part of another annotation (listed in the See Also section):

    @JoinColumn(foreignKey = @ForeignKey(name = "FK_USER"))
    
    0 讨论(0)
提交回复
热议问题