-->
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.  [ 8 posts ] 
Author Message
 Post subject: NHibernate changing type
PostPosted: Fri Oct 27, 2006 4:01 am 
Newbie

Joined: Fri Oct 27, 2006 3:41 am
Posts: 8
I am using v.1.2.0.1001

What would cause a class to become:

CProxyTypeWorkListStateMachine_INHibernateProxy_ISerializable2

When I do a object.GetType()?

Here is the mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="StateMachine.WorkList, StateMachine" table="WorkList">

      
      <id name="Id" type="Int64" unsaved-value="0">
         <column name="Id" sql-type="bigint" not-null="true" unique="true" index="PK_WorkList"/>
         <generator class="native" />
      </id>
      
      <discriminator column="Type" type="String"/>
      
      <property name="Name" type="String">
         <column name="Name" length="255" sql-type="varchar" not-null="true"/>
      </property>


      <property name="ValidatorType" type="String">
         <column name="ValidatorType" length="255" sql-type="varchar" not-null="false"/>
      </property>


      <property name="ValidatorAssemblyName" type="String">
         <column name="ValidatorAssemblyName" length="255" sql-type="varchar" not-null="false"/>
      </property>


      <property name="Error"/>
      <property name="OnlyAllowUpdate"/>
      

      
      <property name="Status" column="Status" type="StateMachine.Stat, StateMachine" />
      
      <many-to-one name="State" class="StateMachine.State, StateMachine">
         <column name="StateId" sql-type="bigint" not-null="true"/>
      </many-to-one>
      
      <bag name="Assignments" lazy="true" cascade="all-delete-orphan">
         <key column="WorkListId"/>
         <one-to-many class="StateMachine.Assignment, StateMachine"/>
      </bag>

      <many-to-one name="ExceptionWorkList" class="StateMachine.WorkList, StateMachine" cascade="all">
         <column name="ExceptionWorkListId" sql-type="bigint" not-null="false"/>
      </many-to-one>
      
      <map name="Parameters" table="WorkListParameters" lazy="true" cascade="all-delete-orphan">
         <key column="WorkListId"/>
         <index column="`Key`" type="string"/>
         <element column="`Value`" type="string"/>
      </map>
         
      <subclass name="StateMachine.UserControl, StateMachine">
      </subclass>

      <subclass name="StateMachine.DotNetWorkFlow, StateMachine">

         <property name="WorkFlowType" type="String"/>
         <property name="WorkFlowAssemblyName" type="String"/>
         <property name="InstanceId" type="String"/>
         
         
      </subclass>
            

   </class>
</hibernate-mapping>



Thanks,

Marty


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 7:55 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Lazy loading.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 9:25 am 
Beginner
Beginner

Joined: Sat Sep 09, 2006 5:55 am
Posts: 23
If you want to know the type name of your persistent class, you can always use NHibernateUtil.GetClass(object) in stead of object.GetType().

_________________
Cheers,

Guy Mahieu


Top
 Profile  
 
 Post subject: Casting not working either, this does not seem right
PostPosted: Fri Oct 27, 2006 11:54 am 
Newbie

Joined: Fri Oct 27, 2006 3:41 am
Posts: 8
Also none of my simple casts are not working. It seems like there is something else funny going on here.

dotNetWorkflow = (StateMachine.DotNetWorkFlow)this.WorkItem;

Unable to cast object of type 'CProxyTypeWorkListStateMachine_INHibernateProxy_ISerializable2' to type 'StateMachine.DotNetWorkFlow'.

Also, none of my other classes have this behavior.

Please help, thanks in advance.

Marty


Top
 Profile  
 
 Post subject: Result of upgrade
PostPosted: Fri Oct 27, 2006 9:20 pm 
Newbie

Joined: Fri Oct 27, 2006 3:41 am
Posts: 8
Guys,

I down graded to the old version and all is working well again.

I think the issue is, when using the new version you need to you interfaces for everything. Especially if you are using a lot of subclasses, etc. It appears the new version of dynamicproxy?? changed the way it handles the proxing of classes (this might explain why everything needs to be virtual now??)

This way your objects can be compared to interfaces vs. classes.

These are more questions than facts.

I will have to stay w/ version because I have way to many classes to turn into interfaces.

--

I think people should be warned about this because of the impact.

For me this impact was:

1) Cannot cast objects to their actual type, because of the proxy objects being inserted.

2) Could not use the normal GetType() of the object. This is important because global functions that I use may or may not be working on nhibernate objects.

c) Anywhere else you are using the typing information.



Marty


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 9:41 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
Naturally you cant cast them, as they are different objects.

Just set lazy="false" if your class tag in your .hbm file.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 28, 2006 2:26 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
My understanding of the changes with proxies was nhibernate actually checks on configuration if members of classes are virtual to ensure dynamic proxy can correctly proxy the class. In previous versions, this check never happened and caused errors with dynamic proxy if you tried to execute a non-virtual member of a proxy.

Of coarse to properly create a proxy it needs to proxy a class that can be subclassed ie. non sealed with virtual members, or an interface.

One of the reasons I can't stand Microsoft API's. They never program to interfaces and almost always make some members of there classes for extension non-virtual.


Top
 Profile  
 
 Post subject: With that..
PostPosted: Mon Oct 30, 2006 3:04 pm 
Newbie

Joined: Fri Oct 27, 2006 3:41 am
Posts: 8
I think it should be noted that interfaces should always be used then when creating nhibernate classes then.

Otherwise the new version will cause you a lot of greef.

Marty


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