Java Tutorial/EJB3/Invocation Context
Версия от 17:44, 31 мая 2010; (обсуждение)
Get And Use Invocation Context
File: EmployeeBean.java
import javax.ejb.Stateless;
import javax.interceptor.Interceptors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {
@PersistenceContext(unitName="EmployeeService") private EntityManager manager;
@Interceptors(Profiler.class)
public void doAction(){
Customer cust = new Customer();
cust.setLastName("Bond");
cust.setSsn(1L);
manager.persist(cust);
System.out.println("Saved");
cust = manager.find(Customer.class,1L);
System.out.println(cust.getLastName());
cust.setLastName("new name");
manager.persist(cust);
cust = manager.find(Customer.class,1L);
System.out.println(cust.getLastName());
manager.remove(cust);
}
}