1

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

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
Henry
  • 32,689
  • 19
  • 120
  • 221

4 Answers4

3

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
  • 32,689
  • 19
  • 120
  • 221
1

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
  • 5,088
  • 1
  • 25
  • 31
  • I think composite ID wouldn't work since the IDs in my case are FK's in a many-to-one relationship, right? – Henry Dec 28 '09 at 22:17
  • Yes, I can use an additional ID, but I prefer composite ID, thx – Henry Dec 28 '09 at 22:19
  • 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 Dec 28 '09 at 22:42
0

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
  • 680
  • 4
  • 12
  • 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 Dec 26 '09 at 19:45
0

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

Thizzer
  • 16,153
  • 28
  • 98
  • 139