views:

247

answers:

4

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

A: 

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.

jarofclay
thx, updated, but the problem is.. the ID property is required but can't define it since fieldtype can't be "id" and "many-to-one"
Henry
A: 

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%5Fid=47723
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-compositeid

MrThys
+1  A: 

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.

Arthur Thomas
I think composite ID wouldn't work since the IDs in my case are FK's in a many-to-one relationship, right?
Henry
Yes, I can use an additional ID, but I prefer composite ID, thx
Henry
composite ID would work. It doesn't matter if they are FKs. But relying on composite keys makes things more difficult like in this case.
Arthur Thomas
+1  A: 

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

Henry