i have this application that has many-2-many where the mapping table has additional information. At first I thought the issue was just XDoclet, but now I'm not so sure. I have created a workaround, but an real curious why things dont work the way I expect them to.
Say I have the following (roughly)
table a (int a_id primary key)
table b (int b_id primary key)
table a_b (int a_id not null, int b_id not null, date start_date null, date end_date null, int sort_order null)
I have a and b working fine, xdoclet works, hibernate works all is well in the world. I can do a.getBs() a.setBs() fine. The problem is when I want to do a.getAbs() and a.setAbs(). In an effort to keep all extra data that is in table ab, i have to save and update an ab class, and not do setB(), since that causes a delete and in insert, not to mention that b does not contain the extra fields.
At first i created class ab and used b_id as the id using generator as assigned. This worked for creation purposes and for delete purposes, but failed miserably during updates. Since if you update one ab, it updates for all relations of a to b.
Then I tried to create ab using a composite-id mapping.
<composite-id>
<key-property name=aId column=a_id>
<key-property name=bId column=b_id>
</composite-id>
both property fields are set to true for insert and update. This works spledidly for updates, but fails on inserts (i did not try deletes.) When i do a session.save(ab) I always get an exception that the parameter index out of range, error synchronizing the db with the session.
Why is that. Does anyone know?
I even trimmed down the hbm to only have something like this...
<class
name="AB"
table="a_b"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id>
<key-property name=aId column=a_id>
<key-property name=bId column=b_id>
</composite-id>
<property
name="aId"
type="int"
update="true"
insert="true"
column="a_id"
/>
<property
name="bId"
type="int"
update="true"
insert="true"
column="b_id"
/>
</class>
and watched the sql come out as
insert into ab (a_id, b_id) values (?,?)
before the friendly error is thrown.
I will post the exact code if it helps. I just kinda figured that I am missing something very basic, or I am doing somthing un-supported. I can post concrete examples if it will help. I've searched this forum and the docs and am still at a loss.
Thanks... Russ
btw... hibernate is outstanding imho
|