Skip to content

Qualified EntityManager/EntityManagerFactory injection (aligned with Jakarta Persistence 3.2) #33414

Open
@hantsy

Description

It is great that Spring 6.2 adds initial Jakarta Persistence 3.2 support.

Jakarta Persistence 3.2 brings CDI Inject support for EntityManager and EntityManagerFactory.

Spring should align with this change and add Inject/Autowired support for EntityManager and EntityManagerFactory

@Inject @BookstoreDB
EntityManager bookstoreEM;

@Inject @CustomersDB
EntityManager customersEM;

The @BookstoreDB and CustomersDB are meta-annotations with @Qulifier to identify different persistence unit/datasource. And allow developers to create the EMF factory bean with these qualifiers(1) or properties(2,3) to specify it.

@BookstoreDB // 1
@Bean 
public LocalContainerEntityManagerFactoryBean ...(){

    emf.setQulifierNames(array of string) // 2
    emf.setQulifierClasses(array of classes) // 3
}

By default, only one db data source, all qualifiers can be ignored.

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions