persistence icon indicating copy to clipboard operation
persistence copied to clipboard

Explicitly allow or disallow use of Entity Manager with extended Persistence Context for CDI injection

Open lukasj opened this issue 12 years ago • 7 comments

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.

lukasj avatar Feb 05 '13 06:02 lukasj

  • Issue Imported From: https://github.com/javaee/jpa-spec/issues/46
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @ldemichiel

lukasj avatar Aug 31 '18 16:08 lukasj

@glassfishrobot Commented Reported by donatasc

lukasj avatar Feb 05 '13 06:02 lukasj

@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.

lukasj avatar Feb 22 '13 22:02 lukasj

@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-46

lukasj avatar May 05 '17 06:05 lukasj

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.

m-reza-rahman avatar Apr 27 '21 03:04 m-reza-rahman

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.

gavinking avatar Apr 28 '21 10:04 gavinking

(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.)

gavinking avatar Apr 28 '21 10:04 gavinking

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.

gavinking avatar Aug 12 '23 22:08 gavinking