Java Reference
In-Depth Information
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
protected long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
}
We have not had to add any unusual features to these classes in order to support the
Hibernate tool, though we have chosen to provide package-scoped default constructors to
support use of the (optional) lazy-loading feature of Hibernate. Most existing applications will
contain POJOs “out of the box” that are compatible with Hibernate.
Creating the Object Mappings
Now that we have our POJOs, we need to map them to the database, representing the fields
of each directly or indirectly as values in the columns of the associated tables. We take each
in turn.
The fully qualified name of the type that we are mapping is specified, and the table in
which we would like to store it is specified (we used aduser because user is a keyword in many
databases).
The class has three fields, as follows:
The id field : Corresponds to the surrogate key to be used in, and generated by, the data-
base. This special field is handled by the <id> element. The name of the field is specified
by the name attribute (so that name="id" corresponds as it must with the method name of
"getId" ). It is identified as being of long type, and we would like to store its values in the
database in the long column. We specify that it should be generated by the database,
rather than by Hibernate.
Search WWH ::




Custom Search