JSF 1.2 specification allows injection of an entity manager into a managed bean via the @PersistenceContext annotation (JSR 252, 开发者_StackOverflow中文版p. 5-13).
What is the semantics of such an entity manager regarding transactions and lifecycle?
Is an EAR-scoped JTA-style persistence unit supposed to work here?
@Stateless
public class YourServiceBean implements YourService {
@PersistenceContext(unitName="YourServicePU")
EntityManager em;
// ...
}
This will inject an EntityManager instance that you do not have to dispose of (the container takes care of it) and is supposed to play nice with container-managed transactions.
精彩评论