-->
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.  [ 3 posts ] 
Author Message
 Post subject: Proxy not resolving attribute
PostPosted: Fri Nov 10, 2006 12:04 am 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
I have a simple reference class AccountWarningDescription. All attributes are defined in mapping file with bare minimum configuration. All methods have default access (property), all types are either primitive types or their java equivalents (Integer, String).

Several of these attributes are for internal use only. Basically they are switches or define a sort order.

Within AccountWarningDescription we have a static method that accesses Hibernate and lists all of the instances of the class. They are returned as a list of Hibernate proxies. We want these sorted so we pass them to a Comparator that is an inner class of AccountWarningDescription. Yes I know we could make a named query and sort in there however the 'architect' has decreed a level of abstraction that doesn't permit this easily. So we sort with a comparator which should be easy.

However in the comparator when we issue obj1.getAmcDisplayOrder().compareTo( obj2.getAmcDisplayOrder()) we get a NullPointerException because the getAmcDisplayOrder() returns null.

getAmcDisplayOrder is a basic accessor that returns an Integer and has a column defined properly in the hbm. The hibernate access method is "property". The java accessor has a private modifier.
Code:
<property
    name="amcDisplayOrder"
    type="java.lang.Integer"
    update="true"
    insert="true"
    column="AMC_DISPLAY_ORDER"
    not-null="true"
/>

private Integer getAmcDisplayOrder()
{
    return this.amcDisplayOrder;
}


As soon as we change the modifier to public we have no problem. I've tried changing the hibernate access to "field" but that makes no difference.

Isn't hibernate supposed to resolve attributes as soon as they are accessed via the standard accessor, regardless of whether they are private or public? Section 4.1.1 of the reference doc says:
Quote:
Properties need not be declared public - Hibernate can persist a property with a default, protected or private get / set pair.
I don't see anything else that suggests I won't get a value when I call getAmcDisplayOrder().

Can anyone advise please?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 3:44 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Proxy is an exception, it can not intercept private methods. Change modifier to "default" (no modifier) or force initialization using "Hibernate.initialize(proxy)".


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 12, 2006 6:37 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
OK, thanks for that. A wee bit surprising since now I have to make methods public or package-level when they needn't be. However...

I tried changing the mapping to specify lazy="false" for the class and avoid having a proxy altogether. That worked but we decided that there was a knock-on effect of having to re-examine many-to-one mappings to this class from other classes and decide whether we needed to specify an outer-join qualifier for those. Since we have other things to work on, changing the method modifier was deemed the safest and quickest solution for now.

Thanks again

Andrew


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