-
1. Re: Stateless and Stateful Beans with EntityManager
wdfink Feb 2, 2014 6:14 AM (in response to asotobu)I dit not understand what you are asking for. Could you be a bit more specific?
-
2. Re: Stateless and Stateful Beans with EntityManager
asotobu Feb 3, 2014 4:38 AM (in response to wdfink)Sorry let me explain with an example. You can use EnitytManager as:
@Stateful
public class Movies {
@PersistenceContext
private EntityManager entityManager;Or for example as:
@Stateless
public class Movies {
@PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;What do you think is the best option?
-
3. Re: Re: Stateless and Stateful Beans with EntityManager
abhijithtn Feb 3, 2014 5:17 AM (in response to asotobu)Hi Alex,
Below is the excerpt from JPA specification (Section 7.6.3 - Container managed Extended Persistence Context),
"A container-managed extended persistence context can only be initiated within the scope of a stateful
session bean."
You cannot have extended persistence context in stateless session bean.
Hope this has answered your question
-
4. Re: Re: Stateless and Stateful Beans with EntityManager
asotobu Feb 3, 2014 6:05 AM (in response to abhijithtn)Partly because if you are not using an extended persistence context, then Stateless is still valid.
-
5. Re: Stateless and Stateful Beans with EntityManager
gsahni Dec 19, 2018 10:10 AM (in response to asotobu)Do we have any answer to this? I had a question on the similar lines java - @PersistenceContext With 'Provided' Scope RestController - Stack Overflow Any leads to this? Do have a look at this answer to java - Is EntityManager really thread-safe? - Stack Overflow