Java Reference
In-Depth Information
The entity itself is the
Product
class, this time with a sprinkling of JPA (or Hibernate)
annotations:
@Entity
public class Product {
@Id
private int id;
private String name;
private double price;
// ... constructors ...
// ... getters and setters ...
// ... toString, equals, hashCode ...
}
The
@Entity
and
@Id
annotations declare
Product
to be a class mapped to a database
Product
attribute names and the database column names happen to match, I don't need
the additional physical annotations like
@Table
and
@Column
.
9
Not really.
now the
insertProduct
method returns the new database-generated primary key. The
JpaProductDAO
implementation class is where the action happens, andit'sshowninthe
next listing.