-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: composite-id insert failures... please help
PostPosted: Fri Mar 12, 2004 10:28 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:50 pm
Posts: 45
Location: US: New York NY
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 6:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
<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>
</class>

don't have to duplicate properties...

Have you call the setter method on both attributes before saving?

show code, it could help


Top
 Profile  
 
 Post subject: i found it
PostPosted: Sat Mar 13, 2004 8:03 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:50 pm
Posts: 45
Location: US: New York NY
Thanks for the reply. I was using hibernate 2.0, and was getting along fine with inserts and updates, but deletes failed. I upgraded to latest and all operations work as expected.

FYI, I found another post that helped me..

<hibernate-mapping>
<class name="com.my.AccoSubbBEAN" table="ACCO_SUBCRI">

<composite-id>
<key-property name="acco_id" column="acco_id" type="integer"/>
<key-property name="subb_id" column="subb_id" type="integer"/>
</composite-id>


<property name="accsubb_actif" column="accsubb_actif"/>

<many-to-one name="account" class="com.my.AccountBEAN" column="acco_id" insert="false" update="false" />
<many-to-one name="subscriber" class="com.my.SubscriberBEAN" column="subb_id" insert="false" update="false" />


</class>
</hibernate-mapping>

If you do put a property entry for acco_id or subb_id, make insert and update false, but as per above reply, you don't need them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.