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.  [ 1 post ] 
Author Message
 Post subject: unable to save a collection of values on a 1:N association
PostPosted: Wed Nov 15, 2006 5:39 pm 
Newbie

Joined: Fri Nov 03, 2006 7:01 pm
Posts: 4
This is a bidirectional one-to-many association. The following map works fine when retrieving children if children exist. However, I have been unable to insert a new collection of string values on the parent since no primary key can be generated on the child table.

Here are the table schema and hibernate mapping file:

create table parent (
id number not null,
constraint parent_pk primary key (id)
);

create table child (
id number not null,
parent_id number not null,
comment varchar2(250),
constraint child_pk primary key id,
constraint child_fk foreign key references parent (id)
);


<hibernate-mapping>
<class name="parent" table="parent">
<id name="id" type="long">
<column name="id" />
</id>
<set name="children" table="child">
<key>
<column name="parent_id" />
</key>
<element column="comment" type="string" />
</set>
</class>
</hibernate-mapping>

One solution is to build a Child object and map it to the "child" table and then use <one-to-many class="Child"> tag. But that will result in an extra Java class. Are there any alternatives without creating a new Java class?


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

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.