1
votes

I'm trying to bulk-update entities using a StatelessSession.

Because it's stateless, NHibernate doesn't auto-cascade child entities upon save.

This is fine because I don't want to make any changes to any of the child entities.

Unfortunately, upon save, NHibernate complains:

"object references an unsaved transient instance - save the transient instance before flushing. Type: MyAssembly.MyRandomEntity, Entity: Castle.Proxies.MyRandomEntityProxy"

Of course if I try and update the child entity, I get the error:

"No persister for: Castle.Proxies.MyRandomEntityProxy"

As you can see, the child entity is a proxy because it hasn't been loaded. I don't need it, I don't want to update it... but even if I did I'm not sure how I could.

Any idea how to solve this problem, basically telling it to ignore the transient child entities?

Update

Here is the mapping for the child entity on the parent object:

<many-to-one class="MyAssembly.Flight, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="OutboundFlight">
  <column name="OutboundFlightId" />
</many-to-one>

Here is the Id column on the child entity:

<id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="0">
  <column name="FlightId" />
  <generator class="assigned" />
</id>
1
why is the proxy transient? if its created while retrieving it then the mapping of unsavedvalue is incorrect. Otherwise who is creating it? - Firo
It must be created when retrieving, I'm not touching it. In what way would the mapping be wrong? I'm using Fluent Nhibernate, and not doing anything specific with the mapping of that child entity. - Chris Haines
how does the id-mapping for MyRandomEntity look like? - Firo
hmm that's a good question... I'm using Sharp Architecture (EntityWithTypedId<int>, IHasAssignedId<int>), so it's all hidden... - Chris Haines
Have edited question to include the mappings... does that help? - Chris Haines

1 Answers

1
votes

its using the assigned generator which uses 'unsavedvalue' to know if the instance is peristent or transient. Maybe there really is an Flightobject with id = 0 in the database? Then it would be created as a proxy with Id = 0 which would be treated as transient instance.