我有一个表Incidencia
,其中包含CHAR(1个字节)列visiblemovil
。此列有两个可能的值:“S”或“N”(是/否,西班牙语为si / no)我希望使用boolean
注释转换为@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
我做错了什么?
感谢。
答案 0 :(得分:1)
您的转换器看起来正确。唯一的问题是您的映射中的@Basic
注释。根据定义,@Basic
表示属性将被保留并且将使用标准映射,因此这可能是一个问题(我也没有看到任何强烈的理由混合@Basic
和{在你的情况下{1}}。
@Column
注意:我没有测试过,但应该解决问题。值得尝试将注释移动到字段中,而不是吸气剂。
答案 1 :(得分:1)
您将映射注释放在实体类中映射字段的getter上。 根据{{3}}的第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方法中变量/字段的名称。)
答案 2 :(得分:1)
尝试以下代码段,如果其中一个有效,则可以在不使用任何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"));
答案 3 :(得分:1)
你可以试试这个:
@Column(name = "VISIBLEMOVIL")
@Convert(converter = SiNoToBooleanConverter.class)
private Boolean visiblemovil;
public Boolean getVisiblemovil() {
return visiblemovil;
}
或者如果你想把它放在吸气剂中:
private Boolean visiblemovil;
@Convert(converter = SiNoToBooleanConverter.class, attributeName = "visiblemovil")
public Boolean getVisiblemovil() {
return visiblemovil;
}
在你的转换器上:
@Converter(autoApply = true)
public class SiNoToBooleanConverter ...
最后检查数据库中指定的数据类型。请将帖子包括在问题中,以便我可以验证。 我记得在将enum(在java中)映射到我的转换器Y类型不是整数的tinyint(mysql)时遇到此错误。
答案 4 :(得分:0)
解决。我没有使用@Convert
,而是通过创建自定义类型来解决它。这是解决方案:
Hibernate entities mapping: Retrieve VARCHAR as boolean
感谢raminr
。