Java Reference
In-Depth Information
n Note A surrogate key is an arbitrary value (usually numeric), with the data type depending on the number
of objects expected (e.g., 32-bit, 64-bit, etc.). The surrogate key has no meaning outside the database—it is
not a customer number, a phone number, or anything else. As such, if a business decision causes previously
unique business data to be duplicated, this will not cause problems since the business data does not form
the primary key.
As well as the default constructor for each class, we provide a constructor that allows the
fields other than the primary key to be assigned directly. This allows us to create and populate
an object in one step instead of several, but we let Hibernate take care of the allocation of our
primary keys.
The classes shown in Figure 3-1 are our POJOs. Their implementation is shown in
Listings 3-8, 3-9, and 3-10.
Listing 3-8. The Class Representing Users
package sample.entity;
public class User {
private long id;
private String name;
private String password;
public User(String name, String password) {
this.name = name;
this.password = password;
}
User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
Search WWH ::




Custom Search