hibernate5

时间:2017-01-23 21:07:30

标签: java spring hibernate jpa ucanaccess

我遇到了基于实体的Hibernate生成的别名问题。

@Entity
@Table(name="Base de Clientes")
public class BaseDeClientes{
    @Column(name="1011 Piso")
    private String _1011Piso;

    @Column(name="1011 Status")
    private String _1011Status;

    @Column(name="1011 Hasta")
    private Date _1011Hasta;

    @Column(name="1011 Observ")
    private String _1011Observ;

    @Column(name="Actuación")
    private long _actuacion;

    @Column(name="Año2")
    private long _anio2;

    @Column(name="MontoPN")
    private long montoPN;

    ... A LOT more...
}

Hibernate会生成如下的查询:

select
    this_.[Cod] as Cod1_0_0_,
    this_.[1011 Hasta] as column2_0_0_,
    this_.[1011 Observ] as column3_0_0_,
    this_.[1011 Piso] as column4_0_0_,
    this_.[1011 Status] as column5_0_0_,
    this_.[3r Piso] as column6_0_0_,
    this_.[4o Piso] as column7_0_0_,
    this_.[Actuación] as Actuació8_0_0_
from
    [Base de Clientes] this_ 
where
    this_.[Cod]=?

问题是这个(找不到列Actuació8_0_0_):

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.0 Columna no encontrada: Actuació8_0_0_
    at net.ucanaccess.jdbc.UcanaccessResultSet.getLong(UcanaccessResultSet.java:471)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:300)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2738)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1729)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1655)
    at org.hibernate.loader.Loader.getRow(Loader.java:1544)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727)
    at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
    at org.hibernate.loader.Loader.doQuery(Loader.java:930)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
    at org.hibernate.loader.Loader.doList(Loader.java:2617)
    at org.hibernate.loader.Loader.doList(Loader.java:2600)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
    at org.hibernate.loader.Loader.list(Loader.java:2424)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1774)
    at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
    at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)
    at org.jotapdiez.asintra.dao.ClienteDaoImpl.getByCod(ClienteDaoImpl.java:32)
    at org.jotapdiez.asintra.service.access.AccessServiceImpl.byCod(AccessServiceImpl.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy30.byCod(Unknown Source)
    at org.jotapdiez.asintra.service.access.TestApplication.main(TestApplication.java:25)
Caused by: java.sql.SQLException: Columna no encontrada: Actuació8_0_0_
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCResultSet.findColumn(Unknown Source)
    at org.hsqldb.jdbc.JDBCResultSet.getLong(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessResultSet.getLong(UcanaccessResultSet.java:469)
    ... 38 common frames omitted
Caused by: org.hsqldb.HsqlException: Columna no encontrada: Actuació8_0_0_
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    ... 42 common frames omitted

我认为这是因为重音和其他角色我无法从该数据库中更改任何内容。

在查询中,某些字段是使用columnXX_0_0_这样的别名生成的(因为以数字开头?)而其他字段是使用字段名称中的部分字符串生成的。

我有什么方法可以为别名创建或更改加上前缀columnXX_X_X_

我在ImplicitNamingStrategyPhysicalNamingStrategy上做了很多尝试,但我无法让它发挥作用。

0 个答案:

没有答案