-->
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: key column value not used when adding elements to a bag?
PostPosted: Tue Feb 09, 2010 7:17 am 
Newbie

Joined: Fri Nov 06, 2009 6:45 am
Posts: 2
I've run into some behaviour that seems odd, or maybe I've misunderstood the intentions of mapping bags in Hibernate.

I've got an entity (EntityClass), that has an arbitrary number of values(ValueClass) associated to it, using a bag one-to-many-mapping that specifies a key column, that is part of the table for ValueClass, but is not on the entity, as the association is to be handled by hibernate entirely.

Code:
 
<class name="mypackage.EntityClass" table="entityclass">
    ...
    <bag name="values" cascade="all" >
   <key column="entityclass_id" />
   <one-to-many class="mypackage.ValueClass" />
    </bag>
    ....
</class>

<class name="mypackage.ValueClass" table="valueclass">
    ...
</class>


When I create a new EntityClass instance, and assign values to it, by simply adding them to the values member (List<ValueClass>) on the EntityClass and persist the object, everything works fine, and the entityclass_id field in the table is automatically given the id key of entityclass.

But when I bring up the persisted EntityClass and add new ValueClass-instances to the list, and update/merge, these new instances are indeed persisted, but the entityclass_id field is left blank/null in the database.

Is this expected behaviour, or am I missing something crucial detail here? Can't seem to find any information about this...

If it's so simple that a reply with a letmegooglethatforyou-link is all that is needed, I'm only thankful. (Although, I have of course done quite the bit of googling before posting).

Thank you.


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.