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
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):
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/Linuxjava -version: openjdk version "11.0.4" 2019-07-16mvnw --version or gradlew --version): Apache Maven 3.6.2Additional context
(Add any other context about the problem here.)
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 ?
@Mahaswami You could try https://github.com/lorislab/quarkus-hibernate-types
@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.
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.