Java Reference
In-Depth Information
@Entity
@Table(name = "CUSTOMER")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "CUSTOMER_ID")
private Integer customerId;
@Size(max = 20)
@Column(name = "FIRST_NAME")
private String firstName;
@Size(max = 20)
@Column(name = "MIDDLE_NAME")
private String middleName;
@Size(max = 20)
@Column(name = "LAST_NAME")
private String lastName;
@Size(max = 30)
@Column(name = "EMAIL")
private String email;
public Customer() {
}
public Customer(Integer customerId) {
this.customerId = customerId;
}
//getters and setters omitted for brevity.
}
Notice that the above JPA entity does not use the @GeneratedValue annotation,
therefore the value for its primary key needs to be explicitly set before persisting
its data.
The following CDI Named bean acts as a controller in our example application, it
has a method that is meant to persist data in an instance of the Customer JPA entity.
package com.ensode.nbbook.buggywebapp.controller;
//imports omitted for brevity
@Named
@RequestScoped
@Stateful
public class CustomerController {
@PersistenceContext(unitName = "BuggyWebAppPU")
 
Search WWH ::




Custom Search