Problem with mapping of the annotation @Enumerated(EnumType.STRING)

Description

Dear Hibernate Team,

i am trying to migrate my JavaEE-Web-Application. The current version runs perfectly with Hibernate 4.2.15.Final and JPA 2.0 (using org.hibernate.ejb.HibernatePersistence, PostgreSQL 10, JavaEE 7, Glassfish 3.1.2). However, the migrating to
Hibernate 5.3.0.CR1 (same for 5.2.X versions) and JPA 2.1 (using org.hibernate.jpa.HibernatePersistenceProvider, PostgreSQL 10, JavaEE 8, Glassfish 5) got stucked by mapping problems between Java-Enums and SQL. It looks like that there is a problem with the mapping of the annotation @Enumerated(EnumType.STRING). Hibernates tries to map an enum attribute with that annotation to a varbinary column. I also tried to add additional org.hibernate.type annotations without any success.

So i decided to drill down the problem and created the following small test case which leads me to the conclusion that there must a bug in Hibernate at least for the combination of versions/configurations i have used together (see below together with the explanations what i tried so far).

Any help is highly appreciated. Thanks in advance.

Hibernate creates the following table for the above Class TestEnum:

1) That is, the annotation @Enumerated(EnumType.STRING) seems to be ignored.
Instead of mapping to varchar, Hibernate maps the attribute to varbinary (in postgres to bytea).

2) Then, I was able to create a row in that table via my Web application. However reading the table, i.e. mapping it back from SQL back to Java via Hibernate failed with the following exception.

3) My Next try was to replace the column "type" in the table testenum by a character varying(16) column. The value of the column "type" was changed as needed, too:

Trying to read the table testenum via my Web application now delivered to following exception.

Environment

Hibernate 5.3.0.CR1 (same for 5.2.X versions) and JPA 2.1 (using org.hibernate.jpa.HibernatePersistenceProvider, PostgreSQL 10, JavaEE 8, Glassfish 5)

Activity

Show:
Guillaume Smet
July 11, 2018, 2:25 PM

I mean 5.3.2.Final. So you should use Bytebuddy 1.8.12.

Saurabh Suman
July 12, 2018, 12:39 PM

Thanks Guillaume..I have added the depency for ByteBuddy 1.8.12 and it's resolved now. But I am getting below issue with hibernate 5.3.2. Final version, I am not finding hibernate-infinispan-5.3.2.Final.jar file due to I think I am getting below issue. Could you plz asssist to get that jar file or advise on that below issue?

13:19:16,932 WARN [org.jboss.modules] (MSC service thread 1-2) Failed to define class org.hibernate.cache.infinispan.collection.CollectionRegionImpl in Module "org.hibernate.infinispan" from local module loader @7fe8ea47 (finder: local module finder @226a82c4 (roots: c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules,c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules\system\layers\base)): java.lang.NoClassDefFoundError: Failed to link org/hibernate/cache/infinispan/collection/CollectionRegionImpl (Module "org.hibernate.infinispan" from local module loader @7fe8ea47 (finder: local module finder @226a82c4 (roots: c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules,c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules\system\layers\base))): org/hibernate/cache/spi/CollectionRegion
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_171]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_171]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_171]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [rt.jar:1.8.0_171]
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.Module.loadModuleClass(Module.java:713) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.as.jpa.hibernate5.HibernateSecondLevelCache.addSecondLevelCacheDependencies(HibernateSecondLevelCache.java:92)
at org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.addProviderDependencies(HibernatePersistenceProviderAdaptor.java:107)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deployPersistenceUnitPhaseOne(PersistenceUnitServiceHandler.java:544)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addPuService(PersistenceUnitServiceHandler.java:279)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.handleJarDeployment(PersistenceUnitServiceHandler.java:166)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:136)
at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:52)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165) [wildfly-server-3.0.10.Final-redhat-1.jar:3.0.10.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032) [jboss-msc-1.2.7.SP1-redhat-1.jar:1.2.7.SP1-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955) [jboss-msc-1.2.7.SP1-redhat-1.jar:1.2.7.SP1-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_171]

13:19:16,974 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.subunit."casdm.ear"."server.jar".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."casdm.ear"."server.jar".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of subdeployment "server.jar" of deployment "casdm.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172) [wildfly-server-3.0.10.Final-redhat-1.jar:3.0.10.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032) [jboss-msc-1.2.7.SP1-redhat-1.jar:1.2.7.SP1-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955) [jboss-msc-1.2.7.SP1-redhat-1.jar:1.2.7.SP1-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_171]
Caused by: java.lang.NoClassDefFoundError: Failed to link org/hibernate/cache/infinispan/collection/CollectionRegionImpl (Module "org.hibernate.infinispan" from local module loader @7fe8ea47 (finder: local module finder @226a82c4 (roots: c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules,c:\Software\JBossEAP\jboss-eap-7.1.0\jboss-eap-7.1\modules\system\layers\base))): org/hibernate/cache/spi/CollectionRegion
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_171]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_171]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_171]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [rt.jar:1.8.0_171]
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.Module.loadModuleClass(Module.java:713) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116) [jboss-modules.jar:1.6.0.Final-redhat-1]
at org.jboss.as.jpa.hibernate5.HibernateSecondLevelCache.addSecondLevelCacheDependencies(HibernateSecondLevelCache.java:92)
at org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.addProviderDependencies(HibernatePersistenceProviderAdaptor.java:107)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deployPersistenceUnitPhaseOne(PersistenceUnitServiceHandler.java:544)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addPuService(PersistenceUnitServiceHandler.java:279)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.handleJarDeployment(PersistenceUnitServiceHandler.java:166)
at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:136)
at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:52)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165) [wildfly-server-3.0.10.Final-redhat-1.jar:3.0.10.Final-redhat-1]
... 5 more

Can Türker
July 12, 2018, 12:42 PM

please don't misuse my original issue for a completely non-related
issue. i am getting all these irrelevant emails.

thanks and best regards

can türker.


-----------------------------------------------------------------------
Dr.-Ing. Can Türker tuerker@fgcz.ethz.ch
Functional Genomics Center Zurich phone +41 44 6353900
UZH / ETH Zurich fax +41 44 6353922
Winterthurerstrasse 190, Irchel Y32 H04
CH-8057 Zurich http://www.fgcz.ch/the-center/people/tuerker.html
-----------------------------------------------------------------------

Saurabh Suman
July 12, 2018, 12:54 PM

Hi Can,

Sorry for the inconvenience. I will create another one..Thanks for your response.

Guillaume Smet
July 12, 2018, 12:58 PM

please use our forums instead.

I don't think it is a bug so let's discuss it in the forums first.

(Can, sorry, hopefully the last one)

Assignee

Chris Cranford

Reporter

Can Türker

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.2.15

Components

Affects versions

Priority

Major
Configure