Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quarkus: EntityManager injection with multiple datasources

There is some examples to work with multiple datasources :

@Inject
@DataSource("users")
AgroalDataSource dataSource1;

@Inject
@DataSource("inventory")
AgroalDataSource dataSource2;

but they don't use EntityManager. Is it possible to get something like:

@Inject
@DataSource("users")
EntityManger em1;

@Inject
@DataSource("inventory")
EntityManger em2;

Thanks.

like image 221
mmiicchael Avatar asked Dec 20 '19 19:12

mmiicchael


2 Answers

Using multiple persistence units is not supported yet unfortunately, at least not with the Quarkus configuration approach and properly configuring the units manually is tedious.

You can subscribe to this issue https://github.com/quarkusio/quarkus/issues/2835 to be notified of the progress.

That's definitely something we will work on soon.

like image 122
Guillaume Smet Avatar answered Sep 25 '22 03:09

Guillaume Smet


There is a progress. Original answer from Guillaume has implemented and announced in here(avilable since Quarkus 1.8.0): https://quarkus.io/blog/quarkus-1-8-0-final-released/

Here is portion of my java codes.

@Inject
@PersistenceUnit("dummy1")
EntityManager em;

and here is sample application.properties.

# dummy1
quarkus.datasource."dummy1".db-kind=postgresql
quarkus.datasource."dummy1".username=postgres
quarkus.datasource."dummy1".password=postgres
quarkus.datasource."dummy1".jdbc.url=jdbc:postgresql://localhost:15432/postgres
quarkus.hibernate-orm."dummy1".database.generation=drop-and-create
quarkus.hibernate-orm."dummy1".datasource=dummy1
quarkus.hibernate-orm."dummy1".packages=dev.tkhm.graphbff.infrastructure.dummy1

Also you can check the detail here. https://quarkus.io/guides/hibernate-orm#multiple-persistence-units

like image 42
tkhm Avatar answered Sep 24 '22 03:09

tkhm