@OneToMany没有反向关系,没有连接表?

编程入门 行业动态 更新时间:2024-10-27 09:34:02
本文介绍了@OneToMany没有反向关系,没有连接表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这与类似的问题没有单独连接表的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没有反向关系,没有连接表?

本文发布于:2023-10-19 15:06:19,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   OneToMany

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!