开发者

How to map this link table in cf-orm?

开发者 https://www.devze.com 2022-12-14 22:58 出处:网络
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),

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


Apparently no hbmxml is needed! Awesome...

property name="A" fieldtype="id,many-to-one" cfc="A" fkcolumn="aID";
property name="B" fieldtype="id,many-to-one" cfc="B" fkcolumn="bID";
property name="num" type="numeric";

Thanks to Brian Kotek's answer at: http://groups.google.com/group/cf-orm-dev/msg/a6ccc2194fceb930


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.


I noticed the fkcolumn for property="Bs" should be "bID".

property name="Bs" fieldtype="one-to-many" cfc="B" fkcolumn="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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消