0 Replies Latest reply on Sep 27, 2016 7:27 AM by Luis Omar Mangioni

    Unable to deploy EAR with enum type mapped property due a ClassCastException (SerializedType to CustomType)

    Luis Omar Mangioni Newbie

      I have an issue while deploing an EAR file in glassfish with an enum type property mapped on an entity class.

       

      the problem occurs during deploy process with a simple enum property mapped on an Entity class auditting with envers. Glassfish throws:

      Exception while preparing the app : org.hibernate.type.SerializableType cannot be cast to org.hibernate.type.CustomType

      We are using:

      • hibernate-core:5.2.2.Final (same with 5.2.0 and 5.1.0)
      • hibernate-envers:5.2.2.Final (same with 5.2.0 and 5.1.0)
      • Glassfish 4.1 build 13 (same with Glassfish 4.1.1)

       

      Debuging the code I found that the problem is in org.hibernate.envers.configuration.internal.metadata.BasicMetadataGenerator, line 112:

      parent.addElement( "param" ).addAttribute( "name", EnumType.NAMED ) .setText( "" + !( (EnumType) ( (CustomType) type ).getUserType() ).isOrdinal() );

      the instance type is a SerializedType and can not by cast to CustomType.

       

      The problem does not occur:

      • if deploying on Payara Server 4.1.1.163
      • or if use hibernate 4.3.0
      • or if mark as @NotAudited the enum type properties

       

      The entity code is:

      import ar.gov.santafe.mpa.vesta.organizacion.Agente;
      import ar.gov.santafe.mpa.vesta.organizacion.Dependencia;
      import java.sql.Date;
      import java.sql.Timestamp;
      import java.time.LocalDate;
      import java.time.LocalDateTime;
      import javax.persistence.Column;
      import javax.persistence.DiscriminatorColumn
      import javax.persistence.Entity;
      import javax.persistence.EnumType;
      import javax.persistence.Enumerated;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.Inheritance;
      import javax.persistence.InheritanceType;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
      import org.apache.commons.lang.StringUtils;
      import org.hibernate.envers.AuditTable;
      
      import org.hibernate.envers.Audited;
      
      @Entity
      @Table (name = "publicacion")
      @Inheritance (strategy = InheritanceType.SINGLE_TABLE)
      @DiscriminatorColumn (name = "dtype")
      @Audited
      @AuditTable (schema = "auditoria", value = "publicacion_auditoria")
      @NamedQueries ({
         @NamedQuery (name = "Publicacion.findPublicaciones",
        query = "SELECT P FROM Publicacion P " +
         " ORDER BY P.fechaPublicacion DESC ")})
      public abstract class Publicacion {
      
         @Id
         @Column (name = "id")
         @GeneratedValue (strategy = GenerationType.SEQUENCE,
        generator = "publicacion_seq")
         @SequenceGenerator (name = "publicacion_seq",
        sequenceName = "publicacion_id_seq",
        allocationSize = 1)
         private Integer id;
      
         @Column (name = "titulo", length = 1000, nullable = false)
         private String titulo;
      
         @Column (name = "contenido", nullable = false)
         private String contenido;
      
         @Column (name = "fecha_evento", nullable = true)
         private Date fechaEvento;
      
         @Column (name = "url_externa", nullable = true)
         private String urlExterna;
      
         @Column (name = "nombre_imagen", nullable = true)
         private String nombreImagen;
      
         @Column (name = "distribucion", nullable = false)
         @Enumerated (EnumType.STRING)
         //@NotAudited
         private EnumDistribucionPublicacion distribucion;
      
         @Column (name = "ancho", nullable = false)
         @Enumerated (EnumType.STRING)
         //@NotAudited
         private EnumAnchoPublicacion ancho;
      
         @Column (name = "fecha_publicacion", nullable = false)
         private Date fechaPublicacion;
      
         @Column (name = "fecha_ultima_modificacion", nullable = false)
         private Timestamp fechaUltimaModificacion;
      
         @ManyToOne (optional = false)
         @JoinColumn (name = "agente_publica_id", nullable = false)
         private Agente agentePublica;
      
         @ManyToOne (optional = false)
         @JoinColumn (name = "dependencia_id", nullable = false)
         private Dependencia dependencia;
      
      
      
         /**
        * @deprecated Solo para cumplir con JPA
        */
         @Deprecated
         protected Publicacion () {
         }
      
      
      
         public Publicacion (String titulo, String contenido, LocalDate fechaEvento, String urlExterna,
         String nombreImagen, EnumDistribucionPublicacion distribucion,
         EnumAnchoPublicacion ancho, LocalDate fechaPublicacion, Agente agentePublica,
         Dependencia dependencia)
         throws PublicacionException {
        setTitulo(titulo);
        setContenido(contenido);
        setFechaEvento(fechaEvento);
        setUrlExterna(urlExterna);
        setDistribucion(distribucion);
        setNombreImagen(nombreImagen);
        setAncho(ancho);
        setFechaPublicacion(fechaPublicacion);
        setAgentePublica(agentePublica);
        setDependencia(dependencia);
        fechaUltimaModificacion = Timestamp.valueOf(LocalDateTime.now());
         }
      
      ...
      ...
      ...
      

       

       

      The enum code is:

      package ar.gov.santafe.mpa.vesta.portal;
      
      public enum EnumAnchoPublicacion {
      
        ANCHO_PUBLICACION_SIMPLE("Simple"),
        ANCHO_PUBLICACION_DOBLE("Doble");
      
         private final String nombre;
      
      
      
         private EnumAnchoPublicacion (String nombre) {
         this.nombre = nombre;
         }
      
      
      
         @Override
         public String toString () {
         return nombre;
         }
      
      }

      When the EAR file is deployed on Glassfish 4.1 I get the folowing ClassCastException:

       

      [2016-09-26T12:05:05.326-0300] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=46 _ThreadName=admin-listener(2)] [timeMillis: 1474902305326] [levelValue: 1000] [[
       
      Exception while preparing the app : org.hibernate.type.SerializableType cannot be cast to org.hibernate.type.CustomType
      java
      .lang.ClassCastException: org.hibernate.type.SerializableType cannot be cast to org.hibernate.type.CustomType
        at org
      .hibernate.envers.configuration.internal.metadata.BasicMetadataGenerator.mapEnumerationType(BasicMetadataGenerator.java:112)
        at org
      .hibernate.envers.configuration.internal.metadata.BasicMetadataGenerator.addBasic(BasicMetadataGenerator.java:64)
        at org
      .hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValueInFirstPass(AuditMetadataGenerator.java:223)
        at org
      .hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:348)
        at org
      .hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:382)
        at org
      .hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:687)
        at org
      .hibernate.envers.configuration.internal.EntitiesConfigurator.configure(EntitiesConfigurator.java:95)
        at org
      .hibernate.envers.boot.internal.EnversServiceImpl.doInitialize(EnversServiceImpl.java:154)
        at org
      .hibernate.envers.boot.internal.EnversServiceImpl.initialize(EnversServiceImpl.java:118)
        at org
      .hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings(AdditionalJaxbMappingProducerImpl.java:99)
        at org
      .hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:288)
        at org
      .hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
        at org
      .hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
        at org
      .hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:151)
        at org
      .glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
        at org
      .glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
        at org
      .glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
        at org
      .glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
        at org
      .glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
        at org
      .glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
        at com
      .sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
        at org
      .glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:309)
        at org
      .glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:88)
        at org
      .glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:155)
        at org
      .glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:152)
        at org
      .glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:255)
        at org
      .glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:152)
        at com
      .sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
        at com
      .sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
        at com
      .sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
        at org
      .glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
        at java
      .security.AccessController.doPrivileged(Native Method)
        at javax
      .security.auth.Subject.doAs(Subject.java:360)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
        at java
      .security.AccessController.doPrivileged(Native Method)
        at javax
      .security.auth.Subject.doAs(Subject.java:360)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
        at com
      .sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
        at org
      .glassfish.admin.rest.resources.admin.CommandResource.executeCommand(CommandResource.java:404)
        at org
      .glassfish.admin.rest.resources.admin.CommandResource.execCommandSimpInMultOut(CommandResource.java:234)
        at sun
      .reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun
      .reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun
      .reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
      .lang.reflect.Method.invoke(Method.java:498)
        at org
      .glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
        at org
      .glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
        at org
      .glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
        at org
      .glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
        at org
      .glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
        at org
      .glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387)
        at org
      .glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331)
        at org
      .glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103)
        at org
      .glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
        at org
      .glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org
      .glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org
      .glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org
      .glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org
      .glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org
      .glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
        at org
      .glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
        at org
      .glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
        at org
      .glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:365)
        at org
      .glassfish.admin.rest.adapter.JerseyContainerCommandService$3.service(JerseyContainerCommandService.java:173)
        at org
      .glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:179)
        at com
      .sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
        at com
      .sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
        at org
      .glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
        at org
      .glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
        at org
      .glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
        at org
      .glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org
      .glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
        at org
      .glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
        at org
      .glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
        at org
      .glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
        at org
      .glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org
      .glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
        at org
      .glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
        at org
      .glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
        at org
      .glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
        at org
      .glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
        at org
      .glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
        at org
      .glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
        at java
      .lang.Thread.run(Thread.java:745)
      ]]

      I have searched the issue with no result, any idea about it?

      Thank in advance