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.