I've token the decision of implement a Interceptor as:
Code:
public object IsUnsaved(object entity)
{
if (entity.GetType().Equals(typeof(Model.Moviment)))
{
Model.Moviment moviment = (Model.Moviment)entity;
return moviment.Decision_value == -1;
}
return null;
}
So, I believe that if IsUnsaved function returns
true -> tells NH to do an insert
false -> tells NH to do an update
null -> use default ("is-unsaved" value)
The problem is that when an entity is savedOrUpdated doesn't generates SQL statement. I thought that if IsUnSaved method returns null, NHibernate will use unsaved-value decision.
For example,
Code:
entity = session.get_entity(id);
entity.Location = other_location; <-- So, entity need to be updated!!
entity.movements.Add(new movement(...)); <-- So, movement must be inserted into MOVEMENTS table.
when I execute session.saveOrUpdate(entity), hibernate only generates
INSERT INTO MOVEMENTS VALUES(...) and It should generates :
UPDATE ENTITY ... and an INSERT INTO MOVEMENTS statements
And if I don't add a movement into entity, entity is updated correctly,
So, if I execute
entity = session.get_entity(id);
entity.Location = new Location;
session.saveOrUpdate(entity);
NHibernate generates an UPDATE ENTITY SET ... statement correctly.
What Do I do wrong?
Thanks for all.