Java Reference
In-Depth Information
The set of example classes represents a publisher's catalog of books. You'll start with a sin-
gle class,
Book
, which has no annotations or mapping information. For this example's purposes,
you do not have an existing database schema to work with, so you need to define your rela-
tional database schema as you go.
At the beginning of the example, the
Book
class is very simple. It has two fields,
title
and
pages
; and an identifier,
id
, which is an integer. The title is a
String
object, and
pages
is an
integer. As we go through this example, we will add annotations, fields, and methods to the
Book
class. The complete source code listing for the
Book
and
Author
classes is given at the end
of this chapter—the source files for the rest are available in the source code download for this
chapter on the Apress web site (
www.apress.com
).
Listing 6-3 gives the source code of the
Book
class, in its unannotated form, as a starting
point for the example.
Listing 6-3.
The
Book
Class, Unannotated
package com.hibernatebook.annotations;
public class Book {
private String title;
private int pages;
private int id;
// Getters...
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public int getPages() {
return pages;
}
// Setters...
public void setId(int id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
Search WWH ::
Custom Search