java – @Convert不适用于Hibernate和QueryDSL

前端之家收集整理的这篇文章主要介绍了java – @Convert不适用于Hibernate和QueryDSL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一张表Incidencia,有一个CHAR(1 Byte)列visiblemovil.此列有两个可能的值:“S”或“N”(是/否,西班牙语为si / no)我希望使用@Convert注释转换为布尔值.这是我的代码

转换器:

@Converter
public class SiNoToBooleanConverter implements AttributeConverter<Boolean,String> {

    @Override
    public String convertToDatabaseColumn(Boolean aBoolean) {
        return aBoolean ? "S" : "N";
    }

    @Override
    public Boolean convertToEntityAttribute(String s) {
        return "S".equals(s);
    }
}

实体:

@FilterDef(name = "PREGINCIDENCIA_FILTRO_FECHA",parameters = @ParamDef(name = "ultimaFechaSinc",type = "date"))
@Entity
public class Incidencia {

    private List<Incidenciapreguntas> preguntasList;

    private Integer codincidencia;

    private String descripcion;

    private Double horasfinalizacion;

    @Convert(converter = SiNoToBooleanConverter.class)
    private Boolean visiblemovil;

    private boolean tieneDocumentacion;

    @Id
    @Column(name = "CODINCIDENCIA")
    public Integer getCodincidencia() {
        return codincidencia;
    }

    public void setCodincidencia(Integer codincidencia) {
        this.codincidencia = codincidencia;
    }

    @Basic
    @Column(name = "DESCRIPCION")
    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    @OneToMany(mappedBy = "incidencia")
    @Filter(name = "PREGINCIDENCIA_FILTRO_FECHA",condition = "FMODIFICACION > :ultimaFechaSinc OR FMODIFICACION IS NULL")
    public List<Incidenciapreguntas> getPreguntasList() {
        return preguntasList;
    }

    public void setPreguntasList(List<Incidenciapreguntas> preguntasList) {
        this.preguntasList = preguntasList;
    }

    @Transient
    public boolean isTieneDocumentacion() {
        return tieneDocumentacion;
    }

    public void setTieneDocumentacion(boolean tieneDocumentacion) {
        this.tieneDocumentacion = tieneDocumentacion;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Incidencia that = (Incidencia) o;

        if (codincidencia != null ? !codincidencia.equals(that.codincidencia) : that.codincidencia != null)
            return false;
        if (descripcion != null ? !descripcion.equals(that.descripcion) : that.descripcion != null) return false;
        return true;
    }

    @Override
    public int hashCode() {
        int result = codincidencia != null ? codincidencia.hashCode() : 0;
        result = 31 * result + (descripcion != null ? descripcion.hashCode() : 0);
        return result;
    }

    @Basic
    @Column(name = "HORASFINALIZACION")
    public Double getHorasfinalizacion() {
        return horasfinalizacion;
    }

    public void setHorasfinalizacion(Double horasfinalizacion) {
        this.horasfinalizacion = horasfinalizacion;
    }

//    @Basic
    @Column(name = "VISIBLEMOVIL")
    public Boolean getVisiblemovil() {
        return visiblemovil;
    }

    public void setVisiblemovil(Boolean visiblemovil) {
        this.visiblemovil = visiblemovil;
    }
}

当我执行SELECT语句(使用QueryDSL)时,我收到此错误

org.hibernate.exception.GenericJDBCException: Fail to convert to internal representation
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Fail to convert to internal representation

库:

@Repository
public class IncidenciasDAO extends BaseDAO {

      public List<Incidencia> getIncidencias() {
        QIncidencia qIncidencia = QIncidencia.incidencia;
        JPAQuery query = new JPAQuery(entityManager);
        List<Incidencia> incidencias = query.from(qIncidencia).list(qIncidencia);
        return incidencias;
    }
}

完整的堆栈跟踪

org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:266)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:222)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:274)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO.getIncidencias_aroundBody0(IncidenciasDAO.java:26)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$AjcClosure1.run(IncidenciasDAO.java:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect.ajc$around$org_springframework_cache_aspectj_AbstractCacheAspect$1$2bc714b5proceed(AbstractCacheAspect.aj:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect$1.invoke(AbstractCacheAspect.aj:61)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:180)
    at org.springframework.cache.aspectj.AbstractCacheAspect.ajc$around$org_springframework_cache_aspectj_AbstractCacheAspect$1$2bc714b5(AbstractCacheAspect.aj:65)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO.getIncidencias(IncidenciasDAO.java:22)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$$FastClassByCGLIB$$bd07b3a2.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:58)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:213)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$$EnhancerByCGLIB$$4b7b3a28.getIncidencias(<generated>)
    at com.grupogimeno.senda.movbrigadas.services.IncidenciasService.getIncidencias(IncidenciasService.java:22)
    at com.grupogimeno.senda.movbrigadas.services.rest.IncidenciasResource.getIcidencias(IncidenciasResource.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)2015-03-10 10:53:05,785 WARN  org.hibernate.engine.jdbc.spi.sqlExceptionHelper - sql Error: 17059,sqlState: 99999
2015-03-10 10:53:05,792 ERROR org.hibernate.engine.jdbc.spi.sqlExceptionHelper - Fallo al convertir a representación interna

org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.grupogimeno.senda.commons.filters.BaseBasicAuthLoginFilter.doFilter(BaseBasicAuthLoginFilter.java:64)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
    at org.hibernate.exception.internal.StandardsqlExceptionConverter.convert(StandardsqlExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at $Proxy115.getBoolean(Unknown Source)
    at org.hibernate.type.descriptor.sql.BitTypeDescriptor$2.doExtract(BitTypeDescriptor.java:69)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2705)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1544)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1476)
    at org.hibernate.loader.Loader.getRow(Loader.java:1376)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:643)
    at org.hibernate.loader.Loader.doQuery(Loader.java:853)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:292)
    at org.hibernate.loader.Loader.doList(Loader.java:2381)
    at org.hibernate.loader.Loader.doList(Loader.java:2367)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2197)
    at org.hibernate.loader.Loader.list(Loader.java:2192)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:257)
    ... 61 more
Caused by: java.sql.sqlException: Fallo al convertir a representación interna
    at oracle.jdbc.driver.CharCommonAccessor.getBoolean(CharCommonAccessor.java:185)
    at oracle.jdbc.driver.T4CCharAccessor.getBoolean(T4CCharAccessor.java:697)
    at oracle.jdbc.driver.OracleResultSetImpl.getBoolean(OracleResultSetImpl.java:640)
    at oracle.jdbc.driver.OracleResultSet.getBoolean(OracleResultSet.java:386)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBoolean(NewProxyResultSet.java:2391)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
    ... 86 more
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:266)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:222)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:274)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO.getIncidencias_aroundBody0(IncidenciasDAO.java:26)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$AjcClosure1.run(IncidenciasDAO.java:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect.ajc$around$org_springframework_cache_aspectj_AbstractCacheAspect$1$2bc714b5proceed(AbstractCacheAspect.aj:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect$1.invoke(AbstractCacheAspect.aj:61)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:180)
    at org.springframework.cache.aspectj.AbstractCacheAspect.ajc$around$org_springframework_cache_aspectj_AbstractCacheAspect$1$2bc714b5(AbstractCacheAspect.aj:65)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO.getIncidencias(IncidenciasDAO.java:22)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$$FastClassByCGLIB$$bd07b3a2.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:58)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:213)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    at com.grupogimeno.senda.movbrigadas.daos.IncidenciasDAO$$EnhancerByCGLIB$$4b7b3a28.getIncidencias(<generated>)
    at com.grupogimeno.senda.movbrigadas.services.IncidenciasService.getIncidencias(IncidenciasService.java:22)
    at com.grupogimeno.senda.movbrigadas.services.rest.IncidenciasResource.getIcidencias(IncidenciasResource.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.grupogimeno.senda.commons.filters.BaseBasicAuthLoginFilter.doFilter(BaseBasicAuthLoginFilter.java:64)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.hibernate.exception.GenericJDBCException: Fallo al convertir a representación interna
    at org.hibernate.exception.internal.StandardsqlExceptionConverter.convert(StandardsqlExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at $Proxy115.getBoolean(Unknown Source)
    at org.hibernate.type.descriptor.sql.BitTypeDescriptor$2.doExtract(BitTypeDescriptor.java:69)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2705)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1544)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1476)
    at org.hibernate.loader.Loader.getRow(Loader.java:1376)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:643)
    at org.hibernate.loader.Loader.doQuery(Loader.java:853)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:292)
    at org.hibernate.loader.Loader.doList(Loader.java:2381)
    at org.hibernate.loader.Loader.doList(Loader.java:2367)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2197)
    at org.hibernate.loader.Loader.list(Loader.java:2192)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:257)
    ... 61 more
Caused by: java.sql.sqlException: Fallo al convertir a representación interna
    at oracle.jdbc.driver.CharCommonAccessor.getBoolean(CharCommonAccessor.java:185)
    at oracle.jdbc.driver.T4CCharAccessor.getBoolean(T4CCharAccessor.java:697)
    at oracle.jdbc.driver.OracleResultSetImpl.getBoolean(OracleResultSetImpl.java:640)
    at oracle.jdbc.driver.OracleResultSet.getBoolean(OracleResultSet.java:386)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBoolean(NewProxyResultSet.java:2391)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
    ... 86 more

我究竟做错了什么?

谢谢.

解决方法

您将映射注释放在实体类中映射字段的getter上.
根据 specification的第2.3.1章,这导致了基于财产的访问.

规范声明只应为映射注释getter.但也许这对@Convert注释来说还不够?

您可以尝试注释该字段:

@Entity
public class Incidencia {

    @Column(name = "VISIBLE")
    @Convert(converter = SiNoToBooleanConverter.class)
    private Boolean visible;

    //other fields

    public Boolean getVisible() {
        return visible;
    }

    public void setVisible(Boolean visible) {
        this.visible = visible;
    }

}

(我更正了getter / setter方法中变量/字段的名称.)

猜你在找的Java相关文章