Java Reference
In-Depth Information
private EntityManager em;
@Inject
private CustomerModel customerModel;
public String createCustomer() {
Customer customer = entityFromModel(customerModel);
try {
persist(customer);
return "confirmation";
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(
Level.SEVERE, "exception caught", e);
return "error";
}
}
public void persist(Object object) {
try {
em.persist(object);
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(
Level.SEVERE, "exception caught", e);
throw new RuntimeException(e);
}
}
private Customer entityFromModel(CustomerModel customerModel) {
Customer customer = new Customer();
customer.setFirstName(customerModel.getFirstName());
customer.setLastName(customerModel.getLastName());
return customer;
}
public CustomerModel getCustomerModel() {
return customerModel;
}
public void setCustomerModel(CustomerModel customerModel) {
this.customerModel = customerModel;
}
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
}
 
Search WWH ::




Custom Search