Pages

Customizing Property Access

Customizing Property Access

There are two ways to access the property , one is direct access ( through fields) and another is using getter or setter method of the property.
you can control this default property access behavior using default-access attribute in following xml mapping metadata :

<hibernate-mapping package="com" default-access="property">
- - -
</hibernate-mapping>

There are following values of this attribute. 
default-access="field|property|noop|custom.Class"

You can also control this access strategy on the property element in hibernate xml mapping with access attribute.
<property name="itemName" column="ITEM_NAME" access="property"/>

Noop value is used to map a property that doesn't exist in java persistent class. you can use it to map virtual property in HQL queries.

You can also create your own custom property access strategy by implementing org.hibernate.property.PropertyAccessor interface on a class.

class MyPropertyAccessStrategy implements PropertyAccessor {

@Override
public Getter getGetter(Class arg0, String arg1)
throws PropertyNotFoundException {
return null;
}

@Override
public Setter getSetter(Class arg0, String arg1)
throws PropertyNotFoundException {
return null;
}
}