spring-framework
spring-framework copied to clipboard
Qualified `EntityManager`/`EntityManagerFactory` injection (aligned with Jakarta Persistence 3.2)
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.