如何命名自JPA 2.1以来的ManyToOne引用的外键约束? [英] How to name the foreign key constraint of ManyToOne references since JPA 2.1?

查看:409
本文介绍了如何命名自JPA 2.1以来的ManyToOne引用的外键约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@ org.hibernate.annotations.ForeignKey 已被弃用,但我找不到任何示例,JPA 2.1对应的外观如何?

  @ManyToOne 
@ForeignKey(name =FK_USER)// @ deprecated推荐引入JPA 2.1 {@link javax.persistence。 ForeignKey}来代替。
私人用户用户;

如何在没有弃用注解的情况下执行此操作?

文档解决方案

表示,此注释不能应用于任何内容:


@Target(value = {})


因此,它只能作为另一个注释的一部分使用(列在 部分中):

  @JoinColumn(foreignKey = @ForeignKey(name =FK_USER))


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

@ManyToOne
@ForeignKey(name = "FK_USER") //@deprecated Prefer the JPA 2.1 introduced {@link javax.persistence.ForeignKey} instead.
private User user;

How is this to be implemented without the deprecated annotation?

解决方案

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"))

这篇关于如何命名自JPA 2.1以来的ManyToOne引用的外键约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆