Jonty

Could you give us some more information, e.g. what your domain model is and 
what the mapping looks like - without that it is very difficult to give a 
sensible answer

Paul

----------------------------------------

From: Jonty <[EMAIL PROTECTED]>
Sent: 03 November 2008 10:16
To: nhusers <[email protected]>
Subject: [nhusers] Re: Updating many-to-one relationship references 

Has anyone got any ideas for this? It must be a common scenario.

On Oct 31, 12:49 pm, Jonty wrote:
> We would like to update many-to-one relationships by simply altering
> the ID of the object, but NHibernate throws an error: "identifier of
> an instance of Country was altered from 7 to 8".
>
> What is the normal pattern for updating many-to-one relationships? Is
> it:
>
> var user = session.Get(userID);
> user.Country =
> session.Get(Convert.ToInt32(Request.Form["Country_ID"]));
> user.Manager =
> session.Get(Convert.ToInt32(Request.Form["Manager_ID"]));
> user.State = session.Get(Convert.ToInt32(Request.Form["State
> _ID"]));
> user.Region = session.Get(Convert.ToInt32(Request.Form["State
> _ID"]));
>
> Do we really need to make an extra database call for every child
> object (event though those objects aren't being updated)? In our app
> at the moment the ID's of the many-to-one objects are updated from the
> Request.Form values via automatic deserialization:
>
> var ds = new NameValueDeserializer();
> var entity = session.Get(entityID);
> ds.Deserialize(entity, form);
> session.Update(entity);
>
> So this works generically for all entities. Having to specifically
> load up child objects to save the entity would be an unnecessary
> coding overhead (as well as making extra database calls).
>
> Is there no way round this in configuration, mappings, interceptors,
> etc? Does anyone know why Hibernate has taken this design decision? At
> the moment we have a work around which involves using a component
> wherever we would normally have a many-to-one.



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to