Saturday, December 30, 2006

Entity Management for EJB3 Stateless Session Beans

@Stateless
public class StatelessSessionBean implements LocalInterface {
@PersistenceUnit(name="PUName")
private EntityManager em;
// operations on the entities, such as creating, editing, destroying, and finding.
}
  • Creates a container-managed entity manager.
  • Entity manager is transaction-scoped (meaning persistence contexts are managed by a container-controlled JTA transaction).
  • Entity manager is stateless (which is why they can be stores in any Java EE component).
  • Transaction initiated when the session bean is first invoked, and its lifecycle managed by the container.