|
Hi,
I'm using NHibernate 1.1 right now and I'm having a problem when fetching something I didn't fetch in the first place (using ICriteria) on the same entity with the same session.
Example:
Person can have 1 Address and 1 Car.
The Car can be Sport or Economy (sub-classes) and "lazy" is set to true (for Car class and its subclasses)
First lookup query, I fetch Address only. Works great.
Second query (same session) I lookup the same Person and try to fetch its Car, which happens to be a Sport Car.
Then I try to cast Person.Car as a SportCar but I get a ClassCastException.
Printing the type of Person.Car, I realize it's the INHibernateProxy there.
In the logs I see the Car being "hydrated". So I know it's there somewhere in memory.
I checked the LoadedState of the Person EntityEntry and I realized its associations are not being set since its first load (it has been already loaded indeed, since I made a query for it right before this one).
So what I get is pretty much like the previous result (it's like I get the previous load state).
Loader.GetRow() checks if the entity has already been loaded.
Impl.SessionImpl.InitializeEntity() "resolve" all the associations to the entity and gets called only when the entity is not yet been loaded.
I tried to force the "re-hydration" of the entity but (of course) it doesn't work.
Any ideas?
|