-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: INHibernateProxy
PostPosted: Fri May 19, 2006 12:34 pm 
Newbie

Joined: Fri May 19, 2006 12:25 pm
Posts: 4
Hi,

I would like to understand what the "INHibernateProxy" type means when I get one as a result of a query.

I'm using a Criteria query and one of the type of the results is something like "CProxyTypeXXXXXX_INHibernateProxy_ISerializable2".

The rest of the result is the class I was querying in my Criteria.

Any idea?


NHibernate version:
1.0.2


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 2:25 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
are any of your properties (Classes) or collections (associations) mapped lazy=true?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 5:42 pm 
Newbie

Joined: Fri May 19, 2006 12:25 pm
Posts: 4
devonl wrote:
are any of your properties (Classes) or collections (associations) mapped lazy=true?


Yes.

My schema is like:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="MyCo.Vehicle" assembly="MyCoLib">
<class name="Car" table="Cars" lazy="true">
<id name="CarID" type="long">
<generator class="native" />
</id>
<property name="Name" />
<joined-subclass name="Truck" table="Trucks" lazy="true">
<key column="CarID"/>
<set name="Parts" table="TrucksToParts" fetch="select">
<key column="CarID"></key>
<many-to-many column="partID" class="TruckPart" fetch="select"/>
</set>
</joined-subclass>
</class>
</hibernate-mapping>

I'm querying "Truck" and one of the result is like "CProxyTypeCarVehicle_INHibernateProxy_ISerializable2" and
the rest is of type "MyCo.Vehicle.Truck".


Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 20, 2006 5:17 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It means that the object in the list is only a proxy for the real one. It should behave identically, provided you declared all public members as virtual.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 20, 2006 3:08 pm 
Newbie

Joined: Fri May 19, 2006 12:25 pm
Posts: 4
Thanks for the answer.

But why is it doing that? I mean why just this one and not the rest? Is there a way I can prevent that or do I have to do something like Initialize() on the proxy(ies)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 5:42 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The proxies should already be initialized. Can you post an example of code between OpenSession() and session.Close() that shows the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 12:37 pm 
Newbie

Joined: Fri May 19, 2006 12:25 pm
Posts: 4
So Sergey figured out some actions of mine were creating a proxy for a "super" class and later on the actual object was loaded and turned out to be a subclass. NHibernate thus uses this object from now on but I was keeping a reference to the proxy somewhere.
Later when I wanted to initialize the proxy, NHibernate didn't try to look whether it was already loaded and throws an exception instead.

It looks like the LazyInitializer needed a little help like:

Code:
if( _target == null )
         {
            if( _session == null )
            {
               throw new HibernateException( "Could not initialize proxy - no Session." );
            }
           
            object maybeTarget = _session.GetEntity( new Key(
               _id, _session.Factory.GetPersister( _persistentClass ) ) );
            if( maybeTarget != null ) {
               _target = maybeTarget;
            }
            else if( !_session.IsOpen )
            {
               throw new HibernateException( "Could not initialize proxy - the owning Session was closed." );
            }
            else if( !_session.IsConnected )
            {
               throw new HibernateException( "Could not initialize proxy - the owning Session is disconnected." );
            }
            else
            {
               _target = _session.ImmediateLoad( _persistentClass, _id );
            }
         }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.