Java Reference
In-Depth Information
Once we have created our new data source, database connection, and persistence
unit, we are ready to create our new JPA entity.
We can do so by simply clicking on the Finish button. At this point, NetBeans
generates the source for our JPA entity.
JPA allows the primary field of a JPA entity to map to any column type
( VARCHAR , NUMBER , and so on). It is a best practice to have a numeric
surrogate primary key, that is, a primary key that serves only as an
identifier and has no business meaning in the application. Selecting the
default Primary Key Type of Long will allow a wide range of values to be
available for the primary keys of our entities.
The Customer class has some important things to consider, as highlighted in the
following code:
package com.ensode.jpaweb;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
public void setId(Long id) { = id;
//Other generated methods (equals(), hashCode(), toString())
omitted for brevity
Search WWH ::

Custom Search