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.  [ 2 posts ] 
Author Message
 Post subject: Odd behavior with class ID and proxy
PostPosted: Wed Jan 30, 2008 11:32 am 
Newbie

Joined: Wed Apr 04, 2007 9:40 am
Posts: 12
Good day,

I'm having a strange occurence with the ID of a class.

Hibernate version: 1.0.2

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Competition.Business.CompetitionEntrySlot, Competition.Business" table="t_rel_registration_type" lazy="true">
      <cache usage="nonstrict-read-write"/>
      <id name="ID" column="SlotID" type="int" unsaved-value="0">
         <generator class="native" />
      </id>

      <many-to-one name="Entry" column="EntryID"/>
      <many-to-one name="Registration" column="RegistrationID"/>
      <many-to-one name="SlotType" column="TypeID"/>

   </class>
</hibernate-mapping>


I have a repeater that I bind using the the following code

Code:
dlEditSlots.DataSource = Entry.Slots;
dlEditSlots.Databind();


The .Slots property is an ISet of the type that is declared above in the mapping. A simple many-to-one as shown here:

Code:
         <set name="Slots" table="t_rel_registration_type" inverse="true" cascade="all-delete-orphan" lazy="true"  sort="Competition.Business.SlotSequenceComparator, Competition.Business" >
            <key column="EntryID"/>
            <one-to-many class="Competition.Business.CompetitionEntrySlot, Competition.Business"/>
         </set>


In the repeater, I have a control that shows the ID of the Slot. It all works fine the first time the repeater is bound. Subsequent binds however report the ID as being 0. (While I hate to say 'when it is bound the first time', I haven't found any other way to frame the problem). But the wierd thing is (to me at least) that the other properties of the objects are resolving perfectly fine! For example I display other properties like SlotType.Name, etc. The only difference I can see between which properties are causing problem is that the ID is the only property native to the CompetitionEntrySlot class, but I'll come back to this later.

Suspecting some proxy issues with the reflection the Repeater control might be using, I've tried to force the initialization of the ISet. To no avail, IsInitialized return true.

I tried iterating throught the ISet and trace the IDs, which caused the problem to dissapear (subsequent binds would work fine and display the proper ID instead of 0). (using a foreach() Trace.Write( o.ID ); )

With the debugger, I inspected the ISet before it gets bound. Well, each item in the set was a proxy class. The proxy was reporting a 0 as the ID (when looking at the base class of the proxy). Looking at the __interceptor property of the proxy and drilling from there, I can see that it consider itself initialized indeed (IsUninitialized = false) and that the Identifier property holds the proper ID of my class!

Basically, I'm completely lost. I'd like to understand why this is happening, but I'll settle on a solution to fix my problem other than forcibly iterating throught the Set before binding it.

Thanks for any help,
Alain-Daniel[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 10, 2008 2:04 am 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
This sounds familiar. I've experienced similar issues on occasion and when I researched it in this forum I found that the error was related to the way ASP.NET does data binding. ASP.NET's reflection code was looking for properties in the wrong place on the proxy. It just doesn't handle inheritance very well. One option might be to explicitly cast the data object to the right class and then use a regular property accessor rather than rely on ASP.NET Eval() expressions.


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