-->
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.  [ 2 posts ] 
Author Message
 Post subject: POJOs instance variables and accessor methods
PostPosted: Wed Jan 31, 2007 3:44 pm 
Newbie

Joined: Sun Jan 02, 2005 10:17 pm
Posts: 13
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes (as long as the Delegate gets initialized somehow)

_________________
Max
Don't forget to rate


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