在 hibernate-jpa-api-2.0 下,我可以使用 @PrimaryKeyJoinColumn 和 oneToOne 关系指定外键的名称吗?
我尝试了以下方法,但似乎不起作用。
@OneToOne(optional = false, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn(name = "CARID")
@ForeignKey(name = "FK_CAR_CORP")
public CarEntity getCar() {
return car;
}
请您参考如下方法:
可以使用两个@ForeignKey
注解:
org.hibernate.annotations.ForeignKey (Hibernate annotation)
javax.persistence.ForeignKey (JPA annotation)
Hibernate 4(甚至是最后一个版本)有时无法处理,可能是由于错误、javax.persistence.ForeignKey
注释造成的。
例如,在 Hibernate 4.3.11 中,我们应该在单向关联的 @OneToMany
部分使用 org.hibernate.annotations.ForeignKey
。我们可以在双向关联的@ManyToOne
部分使用javax.persistence.ForeignKey
。
所以你可以尝试使用Hibernate org.hibernate.annotations.ForeignKey 注释。