Allow @PersistenceContext to be used on parameters ot enable constructor injection of EntityManagers
Currently it's not possible to inject EntityManagers into constructors as @PersistenceContext is defined to not be allowed on parameters. it would be cool to enable this as users could then design application components using constructor injection only.
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/72
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: Unassigned
@glassfishrobot Commented Reported by oliver.gierke
@glassfishrobot Commented @arjantijms said: Wouldn't this automatically be possible when those contexts can be injected with @Inject?
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-72
This seems a small and sensible change. Perhaps it could be accommodated in a future, even if minor, release?
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.
So @PersistenceContext / @PeristenceUnit injection is defined at the same level as @Resource and @EJB, and perhaps some others I forget about after all these years. These other annotations don't support constructor/method injection either, so I don't see it as very natural that @PersistenceContext would.
Instead, if you need constructor/method injection, you should use CDI which has always supported this. Assuming that #460 goes through, and provides a slightly easier way to register a persistence unit as injectable via CDI, I would say that this issue is no longer relevant, and can be closed.