1

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>
Chris Haines
  • 6,445
  • 5
  • 49
  • 62
  • why is the proxy transient? if its created while retrieving it then the mapping of unsavedvalue is incorrect. Otherwise who is creating it? – Firo Aug 31 '11 at 15:06
  • 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 Aug 31 '11 at 15:29
  • how does the id-mapping for `MyRandomEntity` look like? – Firo Aug 31 '11 at 15:32
  • hmm that's a good question... I'm using Sharp Architecture (EntityWithTypedId, IHasAssignedId), so it's all hidden... – Chris Haines Aug 31 '11 at 16:24
  • Have edited question to include the mappings... does that help? – Chris Haines Sep 01 '11 at 08:38
  • 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? – Firo Sep 01 '11 at 11:54
  • Ah, I think I know the problem. I have lots of rows with UpgradedFlightID = 0 in the data. These ought to be null... – Chris Haines Sep 05 '11 at 10:53
  • Yes I believe that has solved it. Thanks so much, if you post the answer I'll mark it as correct. – Chris Haines Sep 05 '11 at 11:05

1 Answers1

1

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.

Firo
  • 30,626
  • 4
  • 55
  • 94