Quarkus 3.15.2/3.17.0 with 2 datasources gives "Unable to find datasource '<default>' for persistence unit '<default>'" error #44807
Description
Describe the bug
Iam using Quarkus 3.15.2/3.17.0 with datasources MSSQL(default datasource) and POSTGRESSQL(additional datasource, called "targetdb") and getting stacktrace below.
I use entity managers annotated with org.quarkus.hibernate.orm.PersitenceUnit and want to use the classes of model for both Repositories(which use internal only the annotaded EntityManager) iam not using Panache. EntityManager in the first Repository is annotated with @PersitenceUnit(PersitenceUnit.DEFAULT)
and in the second repository @PersitenceUnit("targetdb")
I try to start quarkus dev with the application-dev.yaml
I also tried with different modelclasses and with panache but as soon I use @PersitenceUnit
annotation i get the same errror.
Expected behavior
Quarkus is working with 2 datasources and shared model classes. Without error.
Actual behavior
Followein error is thrown on startup:
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#configurationDescriptorBuilding threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Unable to find datasource '<default>' for persistence unit '<default>': Datasource '<default>' is not configured. To solve this, configure datasource '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.
at io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil.unableToFindDataSource(PersistenceUnitUtil.java:115)
at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.handleHibernateORMWithNoPersistenceXml(HibernateOrmProcessor.java:866)
at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.configurationDescriptorBuilding(HibernateOrmProcessor.java:332)
at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
at java.base/java.lang.Thread.run(Thread.java:1583)
at org.jboss.threads.JBossThread.run(JBossThread.java:483)
Caused by: io.quarkus.runtime.configuration.ConfigurationException: Datasource '<default>' is not configured. To solve this, configure datasource '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.
at io.quarkus.datasource.common.runtime.DataSourceUtil.dataSourceNotConfigured(DataSourceUtil.java:47)
at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.handleHibernateORMWithNoPersistenceXml(HibernateOrmProcessor.java:867)
... 10 more
How to Reproduce?
Create project with foolwoing settings and execute dev env.
application-dev.yaml
quarkus:
devservices:
enabled: false
datasource:
db-kind: mssql
username: u1
password: p1
jdbc:
url: url1
targetdb:
db-kind: postgresql
jdbc:
url: url2
username: u2
password: p2
hibernate-orm:
database:
generation: none
targetdb:
datasource: targetdb
database:
generation: none
TargetRepository.java
import io.quarkus.hibernate.orm.PersistenceUnit;
@ApplicationScoped
public class TargetRepository {
@Inject
@PersistenceUnit("targetdb")
EntityManager entityManager;
}
SourceRepository.java
import io.quarkus.hibernate.orm.PersistenceUnit;
@ApplicationScoped
public class SourceRepository{
@Inject
@PersistenceUnit(PersistenceUnit.DEFAULT)
EntityManager entityManager;
}
Manager.java
@ApplicationScoped
public class Manager{
@Inject
SourceRepository srepo;
@Inject
TargetRepository srepo;
}
Output of uname -a
or ver
Linux MintPC 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Output of java -version
openjdk 21.0.4 2024-07-16 OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu222.04) OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)
Quarkus version or git rev
3.15.2 / 3.17.0
Build tool (ie. output of mvnw --version
or gradlew --version
)
------------------------------------------------------------ Gradle 8.6 ------------------------------------------------------------ Build time: 2024-02-02 16:47:16 UTC Revision: d55c486870a0dc6f6278f53d21381396d0741c6e Kotlin: 1.9.20 Groovy: 3.0.17 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 21.0.4 (Ubuntu 21.0.4+7-Ubuntu-1ubuntu222.04) OS: Linux 5.15.0-124-generic amd64
Additional information
No response
Activity