Reputation: 41
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.
Upvotes: 4
Views: 6912
Reputation: 880
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
Upvotes: 2
Reputation: 10529
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.
Upvotes: 4