I'm working on a Quarkus application where I need to inject a specific EntityManager based on the environment:
In dev mode, I want to inject the EntityManager from a specific persistence unit ("result-db")
In test mode, I want to inject the default EntityManager without specifying a persistence unit.
I'm going through this because in my test mode i'm only dealing with one data source.
Here’s what I have for dev mode:
@PersistenceUnit("result-db")
EntityManager entityManager;
and for the test mode i want this injection:
@Inject
EntityManager entityManager;
I tried to use the @Produces
and @IfBuildProfile
annotations to achieve environment-specific injection, but it's not working as expected
I'm working on a Quarkus application where I need to inject a specific EntityManager based on the environment:
In dev mode, I want to inject the EntityManager from a specific persistence unit ("result-db")
In test mode, I want to inject the default EntityManager without specifying a persistence unit.
I'm going through this because in my test mode i'm only dealing with one data source.
Here’s what I have for dev mode:
@PersistenceUnit("result-db")
EntityManager entityManager;
and for the test mode i want this injection:
@Inject
EntityManager entityManager;
I tried to use the @Produces
and @IfBuildProfile
annotations to achieve environment-specific injection, but it's not working as expected
1 Answer
Reset to default 0Recently support for deactivated datasource was added to Quarkus (https://quarkus.io/guides/hibernate-orm#persistence-unit-active).
You can configure default
and result-db
PU
in your application.properties
and (de)activate using configuration profiles.