0

With following class,

@Path("/somes")
@RequestScoped
public class SomesResource {

    @PersistenceContext(unitName = "some")
    private EntityManager entityManager;

    @Inject
    private SomeService someService;
}

Where,

@Stateless
public class SomeService {

    @PersistenceContext(unitName = "some")
    private EntityManager entityManager;
}
  • Question 1: Is it O.K. to be injected with @PersistenceContext in @RequestScoped bean?
  • Question 2: Is entityManager in SomesResource need to be worked with an UserTransaction in any modification job?
  • Question 3: Are two entityManagers effectively same instance?
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
  • You already gave answer yourself in 2nd question. A backing bean has no automatic transaction management while an enterprise bean has (i.e. no need to fiddle with `UserTransaction` mess). That's the key difference. Apparently you didn't exactly understand why EJBs exist. This is then food for read: http://stackoverflow.com/questions/18369356/when-is-it-necessary-or-convenient-to-use-springjsf2-or-ejb3jsf2-or-all-of-the – BalusC Oct 09 '15 at 08:42
  • 1
    Java EE 7 specifies a transaction interceptor that you can use to enable transactions in CDI beans. – John Ament Oct 10 '15 at 14:16

0 Answers0