Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus 3.15.2/3.17.0 with 2 datasources gives "Unable to find datasource '<default>' for persistence unit '<default>'" error #44807

Open
nithom1 opened this issue Nov 28, 2024 · 16 comments
Assignees
Labels
area/agroal area/config area/kotlin kind/bug Something isn't working triage/needs-reproducer We are waiting for a reproducer.

Comments

@nithom1
Copy link

nithom1 commented Nov 28, 2024

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

@nithom1 nithom1 added the kind/bug Something isn't working label Nov 28, 2024
Copy link

quarkus-bot bot commented Nov 28, 2024

/cc @geoand (kotlin)

@geoand
Copy link
Contributor

geoand commented Nov 28, 2024

cc @yrodiere @gsmet

@yrodiere yrodiere self-assigned this Nov 28, 2024
@yrodiere
Copy link
Member

yrodiere commented Nov 29, 2024

Thanks for reporting. I created a reproducer here, since I had to: https://github.com/yrodiere/quarkus-playground/tree/i44807

The last commit works around the problem.

Last commit, mvn clean; quarkus dev:

__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2024-11-29 17:32:49,565 INFO  [io.quarkus] (Quarkus Main Thread) code-with-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.17.2) started in 3.312s. Listening on: http://localhost:8080

2024-11-29 17:32:49,566 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2024-11-29 17:32:49,567 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [agroal, cdi, config-yaml, hibernate-orm, jdbc-mysql, jdbc-postgresql, narayana-jta, rest, smallrye-context-propagation, vertx]

git revert HEAD; mvn clean; quarkus dev:

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)
        ... 11 more

So. It would seem that application-dev.yaml is simply ignored -- at least for what matters here, which is build-time properties.

Renaming application-dev.yaml to application.yaml and putting all configuration under "%dev": works fine, so it's not about build-time properties not being taken into account in the dev profile -- it's really about build time properties in application-dev.yaml not being taken into account.

Hey @radcortez, does that make sense to you? Is this a known issue?

@nithom1 as a workaround I'd recommend just moving quarkus.datasource.db-kind and quarkus.datasource."targetdb".db-kind to application.yaml. Because that's probably something you need to do in order for this to work in production anyway... ?

@radcortez
Copy link
Member

Yes, when using profile aware files, we require the main file also to be present:
https://quarkus.io/guides/config-reference#profile-aware-files

I guess that we don't have that clarified in the YAML documentation.

@radcortez
Copy link
Member

Here is an explanation for it:
#37574 (comment)

@nithom1
Copy link
Author

nithom1 commented Dec 2, 2024

@yrodiere it doenst work for me either, I get the same problem, even if I put everything into application.yaml.

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

@nithom1 I just cleaned my workspace and tried your reproducer after applying my workaround again, and moving everything to application.yaml does fix it.
Did you get that problem with my reproducer? If so, what's the exact stacktrace (and logs)?
If you tried with different code, please provide that code (and stacktrace, and logs).

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

Here is an explanation for it: #37574 (comment)

Thanks, that explains the requirement. Would it be technically possible to add a warning, or even fail on bootstrap, when the application.yaml/application.properties doesn't exist but a application-*.yaml/application-*.properties is found? I.e. when an application-* file is going to be ignored? I understand it might not be possible at runtime for performance reasons, but doing this for build time files would be a start?
Should I create an issue?

@nithom1
Copy link
Author

nithom1 commented Dec 2, 2024

@yrodiere
running
./mvnw clean verify

with application.yaml

#"%dev":
quarkus:
  db-kind: mssql
  targetdb:
    db-kind: postgresql
  hibernate-orm:
    packages: 'com.acme'
    targetdb:
      packages: 'com.acme'
      datasource: targetdb

Gives above described error.

[ERROR] 	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#configurationDescriptorBuilding threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Datasource must be defined for persistence unit '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.collectDialectConfig(HibernateOrmProcessor.java:1130)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.producePersistenceUnitDescriptorFromConfig(HibernateOrmProcessor.java:928)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.handleHibernateORMWithNoPersistenceXml(HibernateOrmProcessor.java:852)
[ERROR] 	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.configurationDescriptorBuilding(HibernateOrmProcessor.java:332)
[ERROR] 	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
[ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
[ERROR] 	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:1583)
[ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:499)

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

Counterpoint, when I do this, it works here: https://github.com/yrodiere/quarkus-playground/tree/i44807-nithom1 (it's a new branch, with your exact change)

If you want us to debug please provide an actual, executable project. The problem is not obvious, there's a small detail in your app causing the problem, so it's just wasting everyone's time to exchange claims without ways to investigate.

@radcortez
Copy link
Member

Thanks, that explains the requirement. Would it be technically possible to add a warning, or even fail on bootstrap, when the application.yaml/application.properties doesn't exist but a application-*.yaml/application-*.properties is found? I.e. when an application-* file is going to be ignored? I understand it might not be possible at runtime for performance reasons, but doing this for build time files would be a start?
Should I create an issue?

Yes, I think we can do it. In build time, we can catch all the resources available in the classpath. At runtime we don't need to worry about it because we already did that check. We only need to check the config folder and quarkus.config.locations, which should be a trivial check. Please, create the issue :)

@nithom1
Copy link
Author

nithom1 commented Dec 2, 2024

I dont want so waste someones time!
I checked out your producer project.
I can confirm that i44807-nithom1 works.
But i44807 works not.

Both times built with: ./mvnw clean verify

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

Yes, I think we can do it. In build time, we can catch all the resources available in the classpath. At runtime we don't need to worry about it because we already did that check. We only need to check the config folder and quarkus.config.locations, which should be a trivial check. Please, create the issue :)

Thanks, done: #44871

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

But i44807 works not.

Okay, if you do ./mvnw clean verify I can understand that this would not work, since all the configuration is in the dev profile, which is not enabled when running ./mvnw clean verify.

So you can confirm that the config you posted, where %dev: is commented out, does work? If so everything is working as intended. You can just use https://github.com/yrodiere/quarkus-playground/tree/i44807-nithom1 as a workaround.

@nithom1
Copy link
Author

nithom1 commented Dec 2, 2024

So you can confirm that the config you posted, where %dev: is commented out, does work?

yes

But I can also confirm building with gradle creates this error, also when %dev is commented out:

build.gradle:

plugins {
    id 'java'
    id 'io.quarkus'
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-arc'
    implementation 'io.quarkus:quarkus-hibernate-orm'
    implementation 'io.quarkus:quarkus-jdbc-mssql'
    implementation 'io.quarkus:quarkus-jdbc-postgresql'
    testImplementation 'io.quarkus:quarkus-junit5'
}

group 'com.acme'
version '1.0.0-SNAPSHOT'

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

test {
    systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
compileJava {
    options.encoding = 'UTF-8'
    options.compilerArgs << '-parameters'
}

compileTestJava {
    options.encoding = 'UTF-8'
}

gradle.properties:

# Gradle properties
quarkusPluginId=io.quarkus
quarkusPluginVersion=3.15.2
quarkusPlatformGroupId=io.quarkus.platform
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformVersion=3.15.2

@yrodiere
Copy link
Member

yrodiere commented Dec 2, 2024

So you can confirm that the config you posted, where %dev: is commented out, does work?

yes

But I can also confirm building with gradle creates this error, also when %dev is commented out:

build.gradle:

plugins {
    id 'java'
    id 'io.quarkus'
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-arc'
    implementation 'io.quarkus:quarkus-hibernate-orm'
    implementation 'io.quarkus:quarkus-jdbc-mssql'
    implementation 'io.quarkus:quarkus-jdbc-postgresql'
    testImplementation 'io.quarkus:quarkus-junit5'
}

group 'com.acme'
version '1.0.0-SNAPSHOT'

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

test {
    systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
compileJava {
    options.encoding = 'UTF-8'
    options.compilerArgs << '-parameters'
}

compileTestJava {
    options.encoding = 'UTF-8'
}

gradle.properties:

# Gradle properties
quarkusPluginId=io.quarkus
quarkusPluginVersion=3.15.2
quarkusPlatformGroupId=io.quarkus.platform
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformVersion=3.15.2

Please provide a reproducer. A zip, a link to a GitHub repository -- anything, as long as it's complete. Thank you.

@yrodiere yrodiere added the triage/needs-reproducer We are waiting for a reproducer. label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agroal area/config area/kotlin kind/bug Something isn't working triage/needs-reproducer We are waiting for a reproducer.
Projects
None yet
Development

No branches or pull requests

4 participants