micronaut-projects / micronaut-projects/micronaut-data
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Cannot invoke "String.length()" because "path" is null
@radovanradic is already working on this.
Since Nov 17, 2024.
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
Expected Behavior
I initiated a micronaut project with Kotlin on Java 21 and the following features:
- Micronaut Data Hibernate Reactive
- Liquibase
- Postgres
- JDBC-Hikari
- Testcontainers
I am expecting that the generated test file to work out of the box and the test passes. The test file looks like this:
@MicronautTest
class DemoTest {
@Inject
lateinit var application: EmbeddedApplication<*>
@Test
fun testItWorks() {
Assertions.assertTrue(application.isRunning)
}
}
Actual Behaviour
Instead, I am getting the following error:
Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.boot.SessionFactoryBuilder]
Message: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Cannot invoke "String.length()" because "path" is null
Path Taken: SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) --> SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder([SessionFactoryBuilder sessionFactoryBuilder]) --> SessionFactoryPerJpaConfigurationFactory.buildHibernateSessionFactoryBuilder([Metadata metadata],JpaConfiguration jpaConfiguration)
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.boot.SessionFactoryBuilder]
Looking at the console a bit deeper, it seems that the SQL client URL is not properly calculated:
10:57:13.974 [Test worker] INFO o.h.r.pool.impl.DefaultSqlClientPool - HR000011: SQL Client URL [jdbc:tc:postgresql:16.3:///db]
Notice the literal value jdbc:tc:postgresql:16.3:///db, which should instead look something like this jdbc:postgresql://localhost:55958/test?loggerLevel=OFF (the generated URL of the testcontainer)
Steps To Reproduce
1- Start a Micronaut Projec with Kotlin on Java 21 and Gradle
2- Install the dependencies:
Micronaut Data Hibernate Reactive:
kapt("io.micronaut.data:micronaut-data-processor")
implementation("io.micronaut.data:micronaut-data-hibernate-reactive")
implementation("io.micronaut.data:micronaut-data-tx-hibernate")
implementation("io.micronaut.sql:micronaut-hibernate-reactive")
PostgreSQL DB:
implementation("io.vertx:vertx-pg-client")
runtimeOnly("org.postgresql:postgresql")
Liquibase:
implementation("io.micronaut.liquibase:micronaut-liquibase")
Testcontainers:
testImplementation("org.testcontainers:postgresql")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:testcontainers")
3- Adjust the config files:
application.conf:
liquibase {
datasources {
default {
change-log = "classpath:db/liquibase-changelog.json"
}
}
}
datasources {
default {
db-type = "postgres"
dialect = "POSTGRES"
driverClassName = "org.postgresql.Driver"
password = "${DATABASE_PW:password}"
url = "jdbc:postgresql://${DATABASE_URL:`localhost:5432`}/mydb"
username = "${DATABASE_USER:sa}"
}
}
jpa {
default {
reactive = true
entity-scan {
packages = "com.mstqr.domain"
}
properties {
hibernate {
connection {
db-type = "${datasources.default.db-type}"
password = "${datasources.default.password}"
url = "${datasources.default.url}"
username = "${datasources.default.user}"
}
show_sql = true
hbm2ddl {
auto = "none"
}
}
}
}
}
application-test.conf:
datasources {
default {
driverClassName = "org.testcontainers.jdbc.ContainerDatabaseDriver"
url = "jdbc:tc:postgresql:16.3:///db"
}
}
jpa {
default {
reactive = true
properties {
hibernate {
connection {
driverClassName = ${datasources.default.driverClassName}
url = ${datasources.default.url}
}
hbm2ddl {
auto = "none"
}
}
}
}
}
4- Run any test via ./gradlew test
5- Check the console for the error
Environment Information
JDK version: 21
Kotlin version: 1.9.24
Build Tool: Gradle Kotlin
Test framework: Junit5
Example Application
https://github.com/kareemelzayat/demo-micronaut
Version
4.5.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.