According to many examples it is possible to inject an EntityManager into @Stateless or @Singleton EJBs like this:
@Stateless // or @Singleton
public class MyRepository {
@PersistenceContext
private EntityManager em;
...
}
The EJB 3.1 Spec says that dependency injection is only performed at construction time, so that all callers of MyRepository would use the same instance of EntityManager. How does the EJB container ensure that the correct EntityManager instance is used?