开发者

Meaning of @PersistenceContext in JSF 1.2 Managed Beans

开发者 https://www.devze.com 2023-01-28 05:07 出处:网络
JSF 1.2 specification allows injection of an entity manager into a managed bean via the @PersistenceContext annotation (JSR 252, 开发者_StackOverflow中文版p. 5-13).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消