Skip to content

Injecting EntityManagers through constructor injection (and at non-@PersistenceContext injection points in general) [SPR-10443] #15076

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-10443 and commented

Currently you can inject any Spring bean into clients through constructor injection. A JPA EntityManager is an exception to that. Constructor injection has the benefit of being able to design classes in an immutable way. Also, you communicate required dependencies through it easily. Sadly, @PersistenceContext cannot be used on a constructor parameter and this probably won't change befor JPA 2.2 (giving 2.1 is close to final).

It would be cool to simply be able to inject EntityManager instances through either @Autowired or @Inject.


Issue Links:

  • DATAJPA-445 Enable support to inject EntityManager via constructor

12 votes, 17 watchers

Metadata

Metadata

Assignees

Labels

has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: dataIssues in data modules (jdbc, orm, oxm, tx)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions