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>
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top