-->
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.  [ 4 posts ] 
Author Message
 Post subject: GetType
PostPosted: Thu Jul 12, 2007 10:51 am 
Newbie

Joined: Wed May 02, 2007 9:32 am
Posts: 17
Hi

I have an OrderStatus object that is loaded via nhibernate. I am trying to do some comparisons on it based on its type, but instead of seeing the type i am looking for, I am getting CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1.

Is there a way to determine the type?

Here is the output from GetType()

Code:
? status.GetType()
{Name = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1" FullName = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1"}
    [System.RuntimeType]: {Name = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1" FullName = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1"}
    base {System.Reflection.MemberInfo}: {Name = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1" FullName = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1"}
    Assembly: {DynamicAssemblyProxyGen, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null}
    AssemblyQualifiedName: "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1, DynamicAssemblyProxyGen, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
    Attributes: Public | Serializable
    BaseType: {Name = "OrderStatus" FullName = "Orders.Core.OrderStatus"}
    ContainsGenericParameters: false
    DeclaringMethod: 'status.GetType().DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
    DeclaringType: null
    FullName: "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1"
    GenericParameterAttributes: 'status.GetType().GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException'
    GenericParameterPosition: 'status.GetType().GenericParameterPosition' threw an exception of type 'System.InvalidOperationException'
    GUID: {efb52c8d-8bb8-32ce-bb8e-5f0ecb58f2ac}
    HasElementType: false
    IsAbstract: false
    IsAnsiClass: true
    IsArray: false
    IsAutoClass: false
    IsAutoLayout: true
    IsByRef: false
    IsClass: true
    IsCOMObject: false
    IsContextful: false
    IsEnum: false
    IsExplicitLayout: false
    IsGenericParameter: false
    IsGenericType: false
    IsGenericTypeDefinition: false
    IsImport: false
    IsInterface: false
    IsLayoutSequential: false
    IsMarshalByRef: false
    IsNested: false
    IsNestedAssembly: false
    IsNestedFamANDAssem: false
    IsNestedFamily: false
    IsNestedFamORAssem: false
    IsNestedPrivate: false
    IsNestedPublic: false
    IsNotPublic: false
    IsPointer: false
    IsPrimitive: false
    IsPublic: true
    IsSealed: false
    IsSerializable: true
    IsSpecialName: false
    IsUnicodeClass: false
    IsValueType: false
    IsVisible: true
    MemberType: TypeInfo
    Module: {DynamicAssemblyProxyGen}
    Namespace: null
    ReflectedType: null
    StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
    TypeHandle: {System.RuntimeTypeHandle}
    TypeInitializer: null
    UnderlyingSystemType: {Name = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1" FullName = "CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1"}

Code:
? status
{Orders.Core.OrderStatusPending}

And here is the output when i do a quick ? status
   
[CProxyTypeOrders_CoreOrderStatusCore_NHibernate_ProxyINHibernateProxy1]: {Orders.Core.OrderStatusPending}
    _ISSStatusId: ""
    _OrderStatusDescription: ""
    _OrderStatusId: 0
    ISSStatusId: null
    OrderStatusDescription: "Pending   "
    OrderStatusId: 1


The IDE can "see" it, so its possible, but can anyone tell me how to get "Orders.Core.OrderStatusPending" through code?

Thanks for any help
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 10:59 am 
Newbie

Joined: Wed May 02, 2007 9:32 am
Posts: 17
Found the answer just as after I hit post

<many-to-one name="OrderStatusInformation" class="OrderStatus" column="order_status_id" cascade="none" lazy="false" insert="false" update="false" />

Lazy loading needs to be disabled.

I'd still be interesting in learning how to determine the type.

Thanks
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 11:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
If you call ISession.Get() instead of ISession.Load(), you will never get a proxy. I explained it a bit here:
http://forum.hibernate.org/viewtopic.ph ... 24#2358724

If I am not mistaken, the proxy should be a direct descendant of your OrderStatusPending class. Calling GetType().Parent should give you the Type of OrderStatusPending class. Be aware though, ISession.Load() does not always return a proxy: if you called Get() and the entity has been loaded and cached in the session, calling Load() will return the unproxied entity.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 14, 2007 3:07 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You can can also use NHibernateUtil.GetClass(targetObject) and it will return the type of the object. If the object is lazy it may need to initialize it from the database to determine the type.

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.