连接具有不同连接列名称的两个表
我有两个表 A -> B 具有多对一映射/关联。
表 B 的主键是表 A 中的外键。
问题是两个表中的列名不同。假设 B 有主键列“typeNumId”,它是表 A 中的外键“type”。如何连接该列上的两个表?我如何指定映射来指示表必须连接“typeNumId”和“type”,这本质上是相同的。
特别是通过 hibernate 配置( hbm 文件)可以实现这一点吗?
类似的东西
<many-to-one name="Type" class="com.domain.ProcedureType" update="false" insert="false" fetch="join" lazy="false">
<column name="? <this is in questions? >" not-null="true" />
</many-to-one>
I have two tables A -> B with many-to-one mapping/associations.
Table B's primary key is foreign key in table A.
The problem is column names in both tables are different. let's say B has primary key column "typeNumId" which is foreign key in table A as "type". How can I join both tables on this column? how can I specify mapping to indicate that tables have to join on "typeNumId" and "type" which is essentially same.
especially is this possible through hibernate config ( hbm files) ?
something like
<many-to-one name="Type" class="com.domain.ProcedureType" update="false" insert="false" fetch="join" lazy="false">
<column name="? <this is in questions? >" not-null="true" />
</many-to-one>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ON 子句:
The ON clause:
您可以使用
many-to-one
元素的column
属性或等效的嵌套column
元素来声明外键的名称。从文档中:所以应该这样做:
参考
You declare the name of the foreign key using the
column
attribute of themany-to-one
element or the equivalnent nestedcolumn
element. From the documentation:So something like this should do it:
Reference
像这样的东西吗?
根据您的喜好选择 JOIN 类型
Something like this?
Choose type of JOIN on your taste