这与类似的问题没有单独连接表的Hibernate @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书中提取(查找@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工作 - 在hibernate后面的红帽子部分)
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实现支持 $ b
But it is supported by JPA 2.0 implementation
如果连接是针对使用外键映射策略进行单向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没有反向关系,没有连接表?
发布评论