-->
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: Adding to a map causes insert without id
PostPosted: Wed Mar 21, 2007 5:06 am 
Newbie

Joined: Wed Mar 21, 2007 4:11 am
Posts: 1
Hi,

I'm having trouble putting new entries into a map collection. Getting the map and changing existing entries work fine.

When persisting the map, new entries are inserted without the primary key. Ie. this is what happens:

insert into child (parentid,name,value) values (1,"test","testvalue")

when what should happen is something like this:

insert into child (childid,parentid,name,value) values (child_seq.nextval,1,"test","testvalue")

I could solve this by letting the db add the id itself, but this seems like a pretty common scenario so I guess there must be something wrong with my mapping.

All <map> examples I've come across seem to rely on the child table using PRIMARY KEY(parentid,name), yet this seems to be discouraged as "legacy" db design in all the HIbernate docs I've come across as it would require the mapping for the child to use <composite-id>.

Here are the mappings I use:

Code:
<class name="Parent" table="parent" lazy="false">
  <id name="id" column="parentid">
   <generator class="sequence">
    <param name="sequence">parent_seq</param>
   </generator>
  </id>
 
  <map name="children" table="child" inverse="false">
   <key column="parentid"/>
   <index column="name" type="string"/>
   <element column="value" type="string"/>
  </map>
</class>

<class name="Child" table="child" lazy="false">
  <id name="id" column="childid">
   <generator class="sequence">
    <param name="sequence">child_seq</param>
   </generator>
  </id>

  <many-to-one name="parent" class="Parent" column="parentid" not-null="true"/>
  <property name="ame" column="name"/>
  <property name="value" column="value"/>
</class>


Java code:

Code:
map = parent.getChildren();
map.put("new value","test");
parent.setChildren(map);
session.save(parent);
...


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.