@OneToMany 没有反向关系也没有连接表? [英] @OneToMany without inverse relationship and without a join table?
问题描述
这与在没有单独连接表的情况下休眠@OneToMany"类似的问题",因为我需要一个没有连接表的@OneToMany 关系.但是,我也不想定义逆关系.删除逆似乎会导致自动生成连接表...是否有解决方法?
This is a similar problem to "Hibernate @OneToMany without a separate join table", in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to result in a join table being automatically generated... is there a workaround for this?
推荐答案
在 JPA 2.0+ 中,您可以使用 @JoinColumn 作为避免生成连接表的方法.
In JPA 2.0+ you can use @JoinColumn as a way to avoid to generate joined table.
试试吧.
@OneToMany
@JoinColumn(name="COLUMN_NAME")
更新
以上提供的信息摘自 EJB 3.0 o'reilly book(查找 @JoinColumn 注释引用了 PHONE 表中的 CUSTOMER_ID 列).但是,普通的 JPA 1.0 规范不支持此功能.它说的是
The info provided above has been extracted from EJB 3.0 o'reilly book (Look for The @JoinColumn annotation references the CUSTOMER_ID column in the PHONE table). However, plain JPA 1.0 specification does not support this feature. What it says is
单向一对多关系可以使用一对多外键映射来实现,但是,本版本不需要这种支持.想要对一对多关系使用外键映射策略的应用程序应该使这些关系双向以确保可移植性
Unidirectional one-to-many relationships may be implemented using one-to-many foreign key mappings, however, such support is not required in this release. Applications that want to use a foreign key mapping strategy for one-to-many relationships should make these relationships bidirectional to ensure portability
所以在 1.0 中,它是特定于供应商的实现(这是有道理的,作者在 JBoss 工作 - 休眠背后的红帽部门)
So in 1.0 it is a vendor-specific implementation (And it makes sense, The author works at JBoss - The red hat divison behind the hibernate)
但是它由 JPA 2.0 实现支持
如果连接用于使用外键映射策略的单向 OneToMany 映射,外键在目标实体的表中.
If the join is for a unidirectional OneToMany mapping using a foreign key mapping strategy, the foreign key is in the table of the target entity.
这篇关于@OneToMany 没有反向关系也没有连接表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!