Java Tutorial/EJB3/Interceptors
Interceptors
File: EmployeeBean.java
<source lang="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); }
}</source>