persistence
persistence copied to clipboard
Explicitly allow or disallow use of Entity Manager with extended Persistence Context for CDI injection
CDI specification has so called producer methods, allowing to create (or retrieve) objects to be injected.
JPA specification should explicitly state whether is it allowed for Stateful Session bean to have a producer method that returns extended EntityManager? For example, is this legal:
@ConversationScoped @Stateful public class MyConversationBean { @PersistenceContext(type=EXTENDED) private EntityManager em;
@Produces public EntityManager getEntityManager()
{ return em; }
}
This would be useful if conversation is implemented with several session beans and they all want to share a single extended EntityManager.
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/46
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by donatasc
@glassfishrobot Commented @ldemichiel said: I think this is probably more an EJB issue than a JPA one, but in any case it is something that we should evaluate for the next release.
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-46
The extended persistence context never really took off and is now very out of favor. I would just close this to reduce clutter.
Reza Rahman Jakarta EE Ambassador, Author, Blogger, Speaker
Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.
JPA specification should explicitly state whether is it allowed for Stateful Session bean to have a producer method that returns extended
EntityManager
?
After so many years, I don't remember precisely what we said about stateful session beans, or where we said it. (Does anybody use session beans anymore??!)
However, I believe the functionality described here was always required, right from JPA 1.0/EJB 3.0, but it was defined by the EJB spec, not by the JPA spec.
(And it's certainly the case that CDI lets you bind an extended persistence context to the conversation scope.)
As far as I can see, it's OK if the JPA spec stays silent on these issues.
(Actually there's some ambiguity here. The title of the issue refers to CDI, but then the code example uses @PersistenceContext
to do the injection instead of @Inject
. So I'm not even sure precisely what it is that the issue thinks the JPA spec leaves undefined. Regardless, it's not the job of the JPA spec to define this, AFAICT.)
So I think this is just a dupe of #3 and maybe #377, and so to the extent that there was ever a real "issue" here, it's fixed by #460.