With automatically you mean that hibernate will do that for you ? I don't
think there's a way to achieve that. But what about something like this:
public EntityA {
...
set {
if ( entity != null )
entity.FkEntityB.Remove(this) // or
entitiy.RemoveEntityA(this) if available
entity = value;
if (entity!= null )
entity.FkEntityB.Add(this) // or entity.AddEntityA(this) if
available
}
}
-
Wolfgang
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of antoschka
Sent: Donnerstag, 2. Oktober 2008 10:48
To: nhusers
Subject: [nhusers] how to update inverse bags after adding transient
entities with foreign keys
Hi,
I use one-to-many foreign keys in my entities. e.g. EntityA & EntityB
- EntityB has a Property which references EntityA
"<many-to-one name="EntityA " cascade="none" column="EntityA " not-
null="true" />"
- EntityA has a inverse bag which contains all EntityBs referencing to
EntityA
"<bag name="FkEntityB" inverse="true" lazy="true" cascade="all">
<key column="EntityA " />
<one-to-many class="[class], [assembly]" />
</bag>
The whole thing works fine. The only problem I have is when I add a
transient new EntityB which references EntityA, hhe bag will not be
updated and I have to do it manually, by adding EntityB to the bag-
Collection.
How can this be done automatiaclly without making the new EntityB
persistent?
Tahnska in advance for your help antoschka
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---