Thanks for your quick reply, but I've already saw the mentioned
links.
The last one does not look like a professional solution for my
problem.
The other two requires a lot of coding and additionally Derek has
mentioned some things against the Visitor pattern (http://derek-
says.blogspot.com/2008/05/implementation-of-visitor-pattern-
using.html)

My code that I've posted here is a very simple model of the real
problem that came up during the migration to NHibernate 2.0.1. I'm
using very complex classes with a lot of lists where I must use the
lazy loading.

The thing that is strange for me in the new version of NHibernate is
why NHibernate initializes the communication.Sender entity after a
query as RecipientAProxyXXXXXX if the recipient is type of RecipientC?
It should be RecipientCProxyXXXXXX. Did they re-designed the whole
proxy handling? How can I use it in the old way? I don't like to
rewrite my whole model layer as it contains more hundred complex
classes.

How NHibernate 1.2 handles proxies, does it handle the same way as
NHibernate 2.0.1?
Will pre-generated proxies solve my problem or do they generate the
same proxies as NHibernate does by default?

Thanks



On Apr 1, 4:53 pm, Germán Schuager <[email protected]> wrote:
> http://groups.google.com/group/nhusers/browse_thread/thread/098bba5ba...http://derek-says.blogspot.com/2008/05/implicit-polymorphism-and-lazy...http://mijalko.blogspot.com/2009/03/hibernate-nhibernate-and-polymorp...
>
> On Wed, Apr 1, 2009 at 11:23 AM, domonkos <[email protected]> wrote:
>
> > The situation is the following.
> > I've a recipient class hiearchy like this:
>
> > RecipientA(abstract)
> > RecipientB:RecipientA
> > RecipientC:RecipientA
>
> > Inheritance mapping is: Table per subclass.
>
> > I also have a class which holds a communication entity. This
> > Communication class has
> > a property of type RecipientA (named as Sender) and a property of type
> > string named as SenderName.
>
> > public class Communication
> > {
> >   public virtual RecipientA Sender{get; set;}
> >   public virtual string SenderName{get;}
> > }
>
> > SenderName ppty checks whether the Sender ppty is type of RecipientB
> > or RecipientC and gets
> > the appropriate value from the casted Sender object.
>
> > In the application I run a query for communication objects (with
> > ISession.CreateQuery()) and
> > I'm trying to bind the mentioned SenderName property of each
> > communication object to the UI.
>
> > PROBLEM:
> > After the CreateQuery() - which lists for me the requested
> > Communication objects from DB -
> > all of the Communication objects in the list are holding a
> > RecipientAProxyXXXXXXXX type entity
> > in their Sender property instead of an expected RecipientB or a
> > RecipientC type object.
>
> > I've created a simple "test" to examine the behaviour. I've ran it two
> > different ways:
>
> > FIRST:
>
> > ...
>
> > //Load the communication which holds a RecipientC type object as
> > Sender
> > Communication communication = session.Get<Communication>(6622);
> > session.Evict(communication);
>
> > //Load the RecipientC type object itself with ISession.Get
> > RecipientA recipient1 = session.Get<RecipientA>(19668);
> > session.Evict(recipient1);
>
> > //Load the RecipientC type object itself with ISession.Load
> > RecipientA recipient2 = session.Load<RecipientA>(19668);
> > session.Evict(recipient2);
>
> > ...
>
> > RESULTS (from quick watch):
> > communication.Sender   ID = 19668   RecipientA
> > {RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
> > recipient1                      ID = 19668   RecipientA
> > {RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
> > recipient2                          ID = 19668   RecipientA
> > {RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
>
> > None of the above types are good for me as I expected a RecipientC
> > type for communication.Sender and for recipient1.
>
> > SECOND:
>
> > ...
>
> > //Commented out to check behaviour
> > //Communication communication = session.Get<Communication>(6622);
> > //session.Evict(communication);
>
> > //Load the RecipientC type object itself with ISession.Get
> > RecipientA recipient1 = session.Get<RecipientA>(19668);
> > session.Evict(recipient1);
>
> > //Load the RecipientC type object itself with ISession.Load
> > RecipientA recipient2 = session.Load<RecipientA>(19668);
> > session.Evict(recipient2);
>
> > ...
>
> > RESULTS:
> > recipient1      ID = 19668         RecipientA    {RecipientC}
> > recipient2      ID = 19668   RecipientA
> > {RecipientAProxy0df492d12da94359a34b5e79edc08cf9}
>
> > I this second case recipient1 has the expected type it can be cast to
> > RecipientC.
>
> > How should I handle this? I need to access the SenderName ppty as
> > RecipientB or RecipientC after a query.
> > Why NHibernate loads it as a RecipientAProxy on the communication?
>
> > I'm currently migrating to NHibernate 2.0.1GA and the old version that
> > I've used worked as expected.
> > I've tried it with several inheritance mapping strategies (Table per
> > class, Table per subclass using a discrimiator etc.) the results
> > always were that I've described here.
>
> > The only solution looks like for now is to turn off lazy loading on
> > these entities which is not acceptable.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to