Quarkus: Custom Hibernate Types using reflection not working in native image

Created on 15 Jul 2020  路  5Comments  路  Source: quarkusio/quarkus

Describe the bug
Using custom hibernate type "JsonBinaryType" from com.vladmihalcea:hibernate-types-52 library for jsonb column. Since this library is using reflection internally registered the class for reflection in reflection-config.json.

@TypeDefs({
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@Entity
public class Fruit {
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private Map info;

Error
Getting below exception when the native image is run.

2020-07-15 15:45:49,003 ERROR [io.qua.application] (main) Failed to start application: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.persistenceException(FastBootEntityManagerFactoryBuilder.java:110)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:70)
        at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:54)
        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:110)
        at io.quarkus.hibernate.orm.runtime.JPAConfig.startAll(JPAConfig.java:58)
        at io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder.startAllPersistenceUnits(HibernateOrmRecorder.java:84)
        at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits66.deploy_0(HibernateOrmProcessor$startPersistenceUnits66.zig:51)
        at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits66.deploy(HibernateOrmProcessor$startPersistenceUnits66.zig:70)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:219)
        at io.quarkus.runtime.Application.start(Application.java:89)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:90)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:61)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
Caused by: org.hibernate.MappingException: Could not instantiate Type: com.vladmihalcea.hibernate.type.json.JsonBinaryType
        at org.hibernate.type.TypeFactory.type(TypeFactory.java:113)
        at org.hibernate.type.TypeFactory.byClass(TypeFactory.java:70)
        at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:126)
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:473)
        at org.hibernate.mapping.Property.getType(Property.java:70)
        at org.hibernate.event.service.internal.EventListenerRegistryImpl.prepare(EventListenerRegistryImpl.java:152)
        at org.hibernate.boot.internal.MetadataImpl.initSessionFactory(MetadataImpl.java:376)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:211)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:68)
        ... 15 more
Caused by: java.lang.IllegalArgumentException: java.lang.NoSuchMethodException: org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.getJavaType()
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.handleException(ReflectionUtils.java:582)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getMethod(ReflectionUtils.java:235)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getMethod(ReflectionUtils.java:233)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getMethod(ReflectionUtils.java:233)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getMethod(ReflectionUtils.java:193)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getGetter(ReflectionUtils.java:301)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.invokeGetter(ReflectionUtils.java:367)
        at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.setParameterValues(JsonTypeDescriptor.java:67)
        at com.vladmihalcea.hibernate.type.json.JsonBinaryType.setParameterValues(JsonBinaryType.java:84)
        at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:126)
        at org.hibernate.type.TypeFactory.type(TypeFactory.java:108)
        ... 23 more
Caused by: java.lang.NoSuchMethodException: org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.getJavaType()
        at java.lang.Class.getDeclaredMethod(DynamicHub.java:2475)
        at com.vladmihalcea.hibernate.type.util.ReflectionUtils.getMethod(ReflectionUtils.java:225)
        ... 32 more

Expected behavior
Should be able to use the custom type without issues in native build.

Actual behavior
Exception with native image.
Works in JVM mode successfully.

To Reproduce
Reproducer project can be found at: quarkus-jsonb-column-reproducer

Configuration

# Add your application.properties here, if applicable.
quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json

reflection-config.json

[
  {
    "name" : "com.vladmihalcea.hibernate.type.json.JsonBinaryType",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]

Environment (please complete the following information):

  • Output of uname -a or ver: Linux msuser1 5.0.0-32-generic #34~18.04.2-Ubuntu SMP Thu Oct 10 10:36:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: openjdk version "11.0.4" 2019-07-16
  • GraalVM version (if different from Java): graalvm-ce-java11-20.1.0
  • Quarkus version or git rev: 1.5.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.2

Additional context
(Add any other context about the problem here.)

arehibernate-orm arepersistence kinbug triagduplicate

Most helpful comment

@famod Thank you for referring to this extension. Tried and its working fine.

@Sanne yes, its a duplicate of #9861.. didn't notice this one before.

All 5 comments

cc @Sanne @gsmet

/cc @gsmet, @Sanne

We're currently not supporting the Hibernate Types project as there isn't an extension yet - so I wouldn't classify this as a bug.

Would you agree it's a duplicate of #9861 ?

@famod Thank you for referring to this extension. Tried and its working fine.

@Sanne yes, its a duplicate of #9861.. didn't notice this one before.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hantsy picture hantsy  路  3Comments

nderwin picture nderwin  路  3Comments

blsouthr picture blsouthr  路  3Comments

halhelal picture halhelal  路  3Comments

gastaldi picture gastaldi  路  3Comments