开发者

Updating an entity and ignore child proxies when using NHibernate StatelessSession

开发者 https://www.devze.com 2023-04-01 05:40 出处:网络
I\'m trying to bulk-update entities using a StatelessSession. Because it\'s stateless, NHibernate doesn\'t auto-cascade child entities upon save.

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开发者_Python百科, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消