Java Tutorial/EJB3/Entity Update
Update Entity Bean
File: EmployeeBean.java
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {
@PersistenceContext(unitName="EmployeeService") private EntityManager manager;
public void doAction(){
Customer cust = new Customer();
cust.setFirstName("Joe");
manager.persist(cust);
System.out.println("Saved");
cust = manager.find(Customer.class,cust.getId());
System.out.println(cust.getFirstName());
cust.setFirstName("new Name");
manager.merge(cust);
cust = manager.find(Customer.class,cust.getId());
System.out.println(cust.getFirstName());
}
}