@Convert 不适用于 Hibernate 和 QueryDSL

@Convert doesn't work with Hibernate and QueryDSL

我有一个 table Incidencia 和一个 CHAR(1 字节)列 visiblemovil。此列有 2 个可能的值:"S" 或 "N"(西班牙语中的 yes/no、si/no),我想使用 @Convert 注释将其转换为 boolean .这是我的代码:

转换器:

@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_AbstractCacheAspectbc714b5proceed(AbstractCacheAspect.aj:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect.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_AbstractCacheAspectbc714b5(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.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$b7b3a28.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.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.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_AbstractCacheAspectbc714b5proceed(AbstractCacheAspect.aj:1)
    at org.springframework.cache.aspectj.AbstractCacheAspect.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_AbstractCacheAspectbc714b5(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.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$b7b3a28.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.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.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

我做错了什么?

谢谢。

您的转换器看起来是正确的。唯一的事情是映射中的 @Basic 注释。根据定义,@Basic 告诉属性将被持久化并使用标准映射,所以这可能是一个问题(而且我没有看到任何混合 @Basic@Column 在你的情况下)。

@Column(name = "VISIBLE")
@Convert(converter = SiNoToBooleanConverter.class)
public Boolean getVisible() {
    return visiblemovil;
}

注意:我没有测试过,但应该可以解决问题。也值得尝试将注释移动到字段中,而不是 getter.

您将映射注释放在实体 class 中映射字段的 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 方法中更正了 variable/field 的名称。)

尝试下面的代码片段,如果其中一个有效,您可以在不使用任何 converter@convert:

的情况下实现目标
Expression<String> expr = new CaseBuilder()
    .when(incidencia.getVisible()).then("S")
    .otherwise("N");    

query().from(incidencia).list(incidencia.visible.when(true).then("S").otherwise("N"));

你能试试这个吗:

@Column(name = "VISIBLEMOVIL")
@Convert(converter = SiNoToBooleanConverter.class)
private Boolean visiblemovil;

public Boolean getVisiblemovil() {
  return visiblemovil;
}

或者如果您喜欢将其放在 getter 中:

private Boolean visiblemovil;

@Convert(converter = SiNoToBooleanConverter.class, attributeName = "visiblemovil")
public Boolean getVisiblemovil() {
  return visiblemovil;
}

在您的转换器上:

@Converter(autoApply = true)
public class SiNoToBooleanConverter ...

最后检查数据库中指定的数据类型。请 post 也将其包含在问题中,以便我进行验证。 我记得在将枚举(在 java 中)映射到 tinyint(mysql) 时遇到此错误,其中我的转换器 Y 类型不是整数。

已解决。我没有使用 @Convert,而是通过创建自定义类型来解决它。这是解决方案:

感谢raminr