Dependency lookup
A reference is declared using one of the resource reference annotations: @Resource, @EJB, @PersistenceContext, or @PersistenceUnit.
@Stateless
public class EmployeeServiceBean implements EmployeeService {
@PersistenceContext(unitName="EmployeeService")
EntityManager em;
// ...
}
@Stateful
public class EmployeeServiceBean implements EmployeeService {
@PersistenceUnit(unitName="EmployeeService")
private EntityManagerFactory emf;
private EntityManager em;
@PostConstruct
public void init() {
em = emf.createEntityManager();
}
// ...
}
@Stateless
public class DeptServiceBean implements DeptService {
@EJB(beanName="AuditServiceBean")
AuditService audit;
// ...
}
Transactions
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class ProjectServiceBean implements ProjectService {
// methods in this class manually control transaction demarcation
}
@Stateful
public class ShoppingCartBean implements ShoppingCart {
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void addItem(String item, Integer quantity) {
verifyItem(item, quantity);
// ...
}
// ...
}
CMT or BMT
No comments:
Post a Comment