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?