-->
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.  [ 5 posts ] 
Author Message
 Post subject: many-to-one proxy properties not initialising
PostPosted: Mon Oct 03, 2005 6:21 am 
Newbie

Joined: Mon Oct 03, 2005 6:03 am
Posts: 4
Hi there,
I'm having a problem with many-to-one proxy. The class is lazy loading and a proxy is being returned, however, all the proxy values including the identifier are never initialised when I request the proxy object. I looked at the proxy in a debugger and it looks like:

    Type: CProxyTypeCurrencyInfodal_INHibernateProxy1
    Id: 0
    Name: null


Have I configured something incorrectly? I thought it might be to do with unsaved-value or the definition of my Equals or hashcode, but I've written them using business key equality and using the class properties instead of the class field values as described in 'Hibernate in Action' ... still no joy :(

How do I get the proxy to initialise when values are requested?
Any help appreciated,

Ronan

My class mappings
Code:
///////////////////////////////////////////
// CurrencyInfo mapping
<class
    name="com.luzern.ccc.dal.CurrencyInfo, CCCDbLib"
    table="tblSalesCurrency"   
    lazy="true"
>

    <id
        name="Id"
        type="Decimal"
        column="CurrencyID"
        unsaved-value="0"
    >
        <generator class="identity" />
    </id>

   <property
        name="Name"
        type="System.String"
        column="CurrencyName"
        length="50"
    />

   <set name="SalesChannels" table="tblSalesChannel" cascade="all-delete-orphan" lazy="true">
        <key>           
         <column name="CurrencyID"/>           
        </key>
       <one-to-many class="com.luzern.ccc.dal.SalesChannel, CCCDbLib"/>
    </set>
   </class>

</hibernate-mapping>
///////////////////////////////////////////
// End CurrencyInfo mapping
///////////////////////////////////////////

///////////////////////////////////////////
// Start SalesChannel mapping
///////////////////////////////////////////

<class
    name="com.luzern.ccc.dal.SalesChannel, CCCDbLib"
    table="tblSalesChannel"   
    lazy="true"
>

    <id
        name="Id"
        type="Decimal"
        column="SalesChannelId"
        unsaved-value="-1"
    >
        <generator class="identity" />
    </id>


    <many-to-one
      name="CurrencyInfo"
      class="com.luzern.ccc.dal.CurrencyInfo, CCCDbLib"
      column="Currency"       
      not-null="true"/>   
   
   
  </class>

</hibernate-mapping>

///////////////////////////////////////////
// End SalesChannel mapping
///////////////////////////////////////////
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 7:30 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
For proxies to work, persistent properties of proxied class must be virtual. Is it true for your code?

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon Oct 03, 2005 1:41 pm 
Newbie

Joined: Mon Oct 03, 2005 6:03 am
Posts: 4
Thanks for that Andrew.

Twas exactly what I was doing wrong.

/Ronan


Top
 Profile  
 
 Post subject: How do you make "properties" virtual?
PostPosted: Mon Mar 20, 2006 7:56 pm 
Newbie

Joined: Mon Mar 20, 2006 7:40 pm
Posts: 8
I'm a long time OO developer, and have been using Java for years. I've been writing Hibernate code for a few months, and I seem to have been bitten by this same bug in a few places, but I don't know how to interpret the terminology of the solution that xor provided. I have some fields that I can see in the debugger (in Idea) have had their proxies loaded, but when I try to access the values that are clearly loaded in the proxies, I get null instead.

"virtual" isn't an attribute that I can declare for a Java field or method. I don't see a place to declare "virtual" in the hbm.xml. What do you mean by property? Where do you declare this?

This forum thread

http://forum.hibernate.org/viewtopic.ph ... 41#2297041

uses the same terminology, and it was apparently just as enlightening for jnapier as for you, but I'm not getting it.

The only thing I've been able to make work is declaring the field to be outer-join=true in the parent class. I shouldn't have to do that to get loaded proxies to provide access to the state they've already loaded.

Thanks.

_________________
Chris Hibbert
Prediction Markets
http://zocalo.sourceforge.net/
http://blog.commerce.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 4:37 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Chris, we are talking about NHibernate, i.e. Hibernate for .NET Framework. So you just a bit missed with forum's thread. :)

_________________
Best,
Andrew Mayorov // BYTE-force


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