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
table and identify the primary key, respectively. Because, by an amazing coincidence, [ 9 ] the
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.
The ProductDAO interface is the same as that shown in section 8.1 on JDBC, except that
now the insertProduct method returns the new database-generated primary key. The
JpaProductDAO implementation class is where the action happens, andit'sshowninthe
next listing.
 
Search WWH ::




Custom Search