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<User>(userID);
user.Country =
session.Get<Country>(Convert.ToInt32(Request.Form["Country_ID"]));
user.Manager =
session.Get<User>(Convert.ToInt32(Request.Form["Manager_ID"]));
user.State = session.Get<State>(Convert.ToInt32(Request.Form["State
_ID"]));
user.Region = session.Get<Region>(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<TEntity>(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