Regarding this doc:
https://quarkus.io/guides/hibernate-orm#multiple-persistence-units
Panache entities can be attached to only one persistence unit.
If I have two different entities (PanacheEntityBase) associated to two different tables (and two different databases)
Then I have two Persistence Units, as the docs says:
quarkus.datasource.users.db-kind=postgresql
quarkus.datasource.users.jdbc.url=jdbc:postgresql://url1.postgresql.com
quarkus.datasource.users.username=username
quarkus.datasource.users.password=password
quarkus.hibernate-orm.users.datasource=users
quarkus.hibernate-orm.users.packages=com.model.users
quarkus.datasource.orders.db-kind=postgresql
quarkus.datasource.orders.jdbc.url=jdbc:postgresql://url2.postgresql.com
quarkus.datasource.orders.username=username
quarkus.datasource.orders.password=password
quarkus.hibernate-orm.orders.datasource=orders
quarkus.hibernate-orm.orders.packages=com.model.orders
Also two Repositories, UserRepository and OrderRepository (of type PanacheRepository) and then, two services:
@Inject
@PersistenceUnit("users")
EntityManager entityManager;
@Inject
@PersistenceUnit("orders")
EntityManager entityManager;
Finally, when the app starts:
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.persistence.EntityManager and qualifiers [@PersistenceUnit(value = "users")]
- java member: com.repository.UserRespository#entityManager
- declared on CLASS bean [types=[io.quarkus.hibernate.orm.panache.PanacheRepository<com.model.users.UserEntity>, com.repository.UserRepository, java.lang.Object, com.repository.UserRepository, io.quarkus.hibernate.orm.panache.PanacheRepositoryBase<com.model.users.UserEntity, java.lang.Long>], qualifiers=[@Default, @Any], target=com.repository.UserRespository]
The following beans match by type, but none have matching qualifiers:
- Bean [class=org.hibernate.Session, qualifiers=[@Named(value = "orders"), @io.quarkus.hibernate.orm.PersistenceUnit(value = "orders"), @Any]]
at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:428)
at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:508)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:257)
... 13 more
So can I have two different entities associated to two Persistence Units in Panache? If so, any idea to solve the error?
Version of quarkus: 2.6.0.Final
Thanks in advance
Problem solved, I have another properties file and there was a collision. So It works!