简体   繁体   中英

Meaning of @PersistenceContext in JSF 1.2 Managed Beans

JSF 1.2 specification allows injection of an entity manager into a managed bean via the @PersistenceContext annotation (JSR 252, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM