如何在cf-orm中映射这个链接表?
A 1----* A_B **---1 B
表 A 有 aID (PK),表 B 有 bID (PK), 表A_B有:
aID(PK,FK), bID(PK,FK), num
我尝试过
property name="A" fieldtype="many-to-one" cfc="A" fkcolumn="aID";
property name="B" fieldtype="many-to-one" cfc="B" fkcolumn="bID";
property name="num" type="numeric";
,但 CF 一直要求我提供 ID 列...我该怎么办? FK应该是PK。
如果在CFC中无法指定,那么如何在hbm xml中表示这个链接表?
谢谢
A 1---* A_B *---1 B
Table A has aID (PK), Table B has bID (PK),
table A_B has:
aID (PK, FK),
bID (PK, FK),
num
I tried
property name="A" fieldtype="many-to-one" cfc="A" fkcolumn="aID";
property name="B" fieldtype="many-to-one" cfc="B" fkcolumn="bID";
property name="num" type="numeric";
but CF keep asking me for an ID column... what can I do? The FK's should be the PK's.
If there's no way to specify it in CFC, how to represent this link table in hbm xml?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然不需要 hbmxml!太棒了...
感谢 Brian Kotek 在以下位置的回答:http://groups .google.com/group/cf-orm-dev/msg/a6ccc2194fceb930
Apparently no hbmxml is needed! Awesome...
Thanks to Brian Kotek's answer at: http://groups.google.com/group/cf-orm-dev/msg/a6ccc2194fceb930
您能否更改该表,使其具有唯一的自动生成的 ID?主键应该是唯一的并且永远不会改变。 (链接映射键的一部分可能在技术上发生变化)此外,最好使用代理键而不是复合键,因为您可以通过主键而不是复合列来唯一标识记录。
我使用 Hibernate,所有链接表都有自己的代理主键。否则,您将不得不处理 复合 ID 映射声明。
Can you alter the table so that it has a unique, auto generated id? Primary keys should be unique and never change. (part of a link mapping keys could technically change) Also it is best to have a surrogate key instead of composite keys since you can unique identify a record by a primary key instead of composite columns.
I use Hibernate and all my link tables have their own surrogate primary keys. Otherwise you will have to deal with the composite id mapping declaration.
我注意到 property="Bs" 的 fkcolumn 应该是“bID”。
我从您的模式中注意到的另一件事是我相信链接表确实具有多对一,因为链接表中有许多项目链接到 A 表和 B 表中的一个项目。尝试切换到“多对一”,看看是否有帮助。
I noticed the fkcolumn for property="Bs" should be "bID".
The other thing I noticed from your schema is I believe the link table really has a many-to-one as there are many items in the link table which link to one item in the A table and B table. Try switching to a "many-to-one" and see if that helps.
您可以尝试使用复合 id,确实找不到很好的示例,但这里有两个参考;
http://www.theserverside.com/discussions/thread.tss?thread_id= 47723
http://docs. jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-compositeid
You can try using a composite id, couldn't really find a very good example, but here are a two references;
http://www.theserverside.com/discussions/thread.tss?thread_id=47723
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-compositeid