quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Hibernate Custom Usertype failing on startup #20712

Closed jkalex-git closed 2 years ago

jkalex-git commented 3 years ago

Describe the bug

The application fails to start when there is custom usertype defined in a Hibernate entity class. It uses 'hibernate-types-55' for the usertype implementation. The issue is reproducible with any org.hibernate.usertype.UserType implementations. It is not specific to hibernate-types-55 library. The test project is built on top of hibernate-orm-panache-quickstart

Expected behavior

Application starts without errors.

Actual behavior

Error Stacktrace:
2021-10-12 21:52:11,062 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:71)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:103)
    at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:404)
    at org.hibernate.mapping.Column.getSqlType(Column.java:238)
    at org.hibernate.tool.schema.internal.StandardTableExporter.getSqlCreateStrings(StandardTableExporter.java:96)
    at org.hibernate.tool.schema.internal.StandardTableExporter.getSqlCreateStrings(StandardTableExporter.java:30)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:316)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:167)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:136)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:122)
    at org.hibernate.tool.hbm2ddl.SchemaExport.doExecution(SchemaExport.java:314)
    at io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleInfoSupplier.generateDDL(HibernateOrmDevConsoleInfoSupplier.java:74)
    at io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleInfoSupplier.pushPersistenceUnit(HibernateOrmDevConsoleInfoSupplier.java:35)
    at io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleIntegrator.integrate(HibernateOrmDevConsoleIntegrator.java:15)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:292)
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:74)
    at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:67)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:149)
    at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:58)
    at java.base/java.lang.Thread.run(Thread.java:829)

How to Reproduce?

Run the test project https://github.com/jkalex-git/quarkus-hibernate-test

Output of uname -a or ver

No response

Output of java -version

openjdk version "11.0.11"

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.3.0.FINAL

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3

Additional information

This issue is not there in the production app which is running Quarkus Ver# 2.1.1.Final. Please find below vault and datasource configuration

quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
%dev.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/blah
quarkus.datasource.credentials-provider=postgres
%dev.quarkus.vault.url=http://localhost:8200
%dev.quarkus.vault.authentication.client-token=dev-token
%dev.quarkus.vault.credentials-provider.postgres.database-credentials-role=postgres-blah

Issue showed up when upgraded to Quarkus Ver# 2.2.x.Final.

But the issue is reproducible in the test project even with ver#2.1.x, which make me wonder if its related to dev services related with datasources. Prior Ver#2.2.x no dev services were loading with the same configuration as above. This inference may be completely bogus.

quarkus-bot[bot] commented 3 years ago

/cc @Sanne, @gsmet, @yrodiere

jkalex-git commented 2 years ago

Workaround: In application.properties %dev.quarkus.hibernate-orm.dialect=com.blah.persistence.entity.PostgresSQL10ListDialect

New class PostgresSQL10ListDialect

package com.blah.persistence.entity.PostgresSQL10ListDialect;

import io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect;

import java.sql.Types;

public class PostgresSQL10ListDialect extends QuarkusPostgreSQL10Dialect {
    public PostgresSQL10ListDialect() {
        super();
        registerColumnType(Types.ARRAY, "array" );
    }
}
jkalex-git commented 2 years ago

I have tried to disable all dev services quarkus.devservices.enabled=false But it has no effect on the error. The 'HibernateOrmDevConsoleIntegrator' still continues to load in hibernate-core (org.hibernate.internal.SessionFactoryImpl) 2 3 0 FINAL

If I downgrade quarkus 2.1.1.Final, it is not loaded even without quarkus.devservices.enabled=false when you have datasource url defined 2 1 1 FINAL

yrodiere commented 2 years ago

The specific exception you included in the description should disappear with #21147 .

That being said, the underlying cause is that Hibernate ORM is unable to generate your database schema when you're using custom types.

I see in your reproducer that you enabled database schema generation. Is that intentional? Are you successfully using database schema generation in Quarkus 2.1, with custom types?

jkalex-git commented 2 years ago

Thank you for the update.

The reproducer has the same issue with Quarkus 2.1.

The production application uses Quarkus 2.1 without schema generation is working without any issues. Upgrading the Quarkus version causes the application to fail even though there is no change to any other settings.

yrodiere commented 2 years ago

The production application uses Quarkus 2.1 without schema generation

Alright. Then #21147 will fix this issue. The bugfix will be included in Quarkus 2.4.1. Closing.

Thank you for your feedback!