Hello everybody,
In Hibernate's reference guide, it is stated that by default, Hibernate will use a POJO's accessor methods (getters/setters) and not the instance variables directly. Does this imply that if I were to have a POJO with only accessor methods and *no* instance variables defined, Hibernate can still persist that POJO (entity) correctly?
For example, let's say I have the POJO "Yoohoo" defined as:
public class Yoohoo {
private Long id;
private Delegate delegate;
// getters and setters for the 'id' property defined here....
public int getAge() {
return delegate.getAge();
}
public void setAge(int age) {
delegate.setAge(age);
}
}
Notice that the POJO Yoohoo only defines getter/setter and no instance variable for the property "age". My Yoohoo class is actually calling a delegate class to get and set the age.
In addition, I have the following mapping in Yoohoo.hbm.xml:
<hibernate-mapping>
<class name="Yoohoo" table="YOOHOO">
<id name="id" type="long" column="ID"/>
<property name="age" type="int" column="AGE" access="property"/>
</class>
</hibernate-mapping>
My questions is: will Hibernate work correctly with this POJO that has only accessor methods and no corresponding instance variable for the property "age"? Can Hibernate persist, retrieve, and set the "age" property of the Yoohoo class properly?
Thanks in advance. :)
Hibernate version: 3.1
Name and version of the database you are using: Oracle 10g
|