使用Hibernate 3.2.6和DB2查询错误:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL错误:SQLCODE = -204,SQLSTATE = 42704

时间:2016-05-30 09:26:30

标签: hibernate spring-mvc hql

我想根据使用Hibernate和DB2的选择列出总记录。

Hibernate版本: hibernate-3.2.6

DB2版本: db2jcc-9.7.4

如果我使用HQL查询

from AudTrailBean

它执行正常,但如果我尝试查询where condition

from AudTrailBean where rcvFeederSysId='GRF'

它会抛出错误。

错误仅发生在DB2数据库中,MySQL一切正常,没有任何错误。

这是我的代码。

AudTrailBean:

@Entity
@Table(name = "aud_trail")
public class AudTrailBean {
    private static final long serialVersionUID = -6898685332089128609L;

    @Column(name = "RCV_FEEDER_SYS_ID", length = 5)
    private String rcvFeederSysId;

    @Column(name = "REC_STA_TYPE_CD", length = 3)
    private String recStaTypeCd;

    @Column(name = "THUNDERHEAD_CALL_TS")
    private Timestamp thunderheadCallTs;

    @Id
    @Column(name = "AUD_TRAIL_REC_ID", unique = true, nullable = false)
    private Long audTrailRecId;

    @Column(name = "MSG_POLLING_TS", nullable = false)
    private Timestamp msgPollingTs;

    @Column(name = "JAVA_MESSAGING_SRVC_TS", nullable = false)
    private Timestamp javaMessagingSrvcTs;

    @Column(name = "RCV_TMPLT_ID", length = 15)
    private String rcvTmpltId;

    @Column(name = "CORRL_ID", length = 51)
    private String corrlId;

    @Column(name = "RCV_COMMUN_ID", length = 50)
    private String rcvCommunId;

    @Column(name="AUD_TRAIL_REC_2_ID")
    private String audTrailRec2id;

    public String getRcvFeederSysId() {
        return this.rcvFeederSysId;
    }

    public void setRcvFeederSysId(String rcvFeederSysId) {
        this.rcvFeederSysId = rcvFeederSysId;
    }


    public String getRecStaTypeCd() {
        return this.recStaTypeCd;
    }

    public void setRecStaTypeCd(String recStaTypeCd) {
        this.recStaTypeCd = recStaTypeCd;
    }

    public AudTrailBean withStatus(String recStaTypeCd) {
        setRecStaTypeCd(recStaTypeCd);
        return this;
    }


    public Timestamp getThunderheadCallTs() {
        return this.thunderheadCallTs;
    }

    public void setThunderheadCallTs(Timestamp thunderheadCallTs) {
        this.thunderheadCallTs = thunderheadCallTs;
    }


    public Long getAudTrailRecId() {
        return this.audTrailRecId;
    }

    public final void setAudTrailRecId(Long audTrailRecId) {
        this.audTrailRecId = audTrailRecId;
    }


    public Timestamp getMsgPollingTs() {
        return this.msgPollingTs;
    }

    public void setMsgPollingTs(Timestamp msgPollingTs) {
        this.msgPollingTs = msgPollingTs;
    }


    public Timestamp getJavaMessagingSrvcTs() {
        return this.javaMessagingSrvcTs;
    }

    public void setJavaMessagingSrvcTs(Timestamp javaMessagingSrvcTs) {
        this.javaMessagingSrvcTs = javaMessagingSrvcTs;
    }


    public String getRcvTmpltId() {
        return this.rcvTmpltId;
    }

    public void setRcvTmpltId(String rcvTmpltId) {
        this.rcvTmpltId = rcvTmpltId;
    }


    public String getCorrlId() {
        return this.corrlId;
    }

    public void setCorrlId(String corrlId) {
        this.corrlId = corrlId;
    }


    public String getRcvCommunId() {
        return this.rcvCommunId;
    }

    public void setRcvCommunId(String rcvCommunId) {
        this.rcvCommunId = rcvCommunId;
    }


    public String getAudTrailRec2id() {
        return audTrailRec2id;
    }

    public void setAudTrailRec2id(String audTrailRec2id) {
        this.audTrailRec2id = audTrailRec2id;
    }


    public AudTrailBean() {
    }

    public AudTrailBean(Long id) {
        setAudTrailRecId(id);
    }

    public AudTrailBean(String id) {
        setAudTrailRecId(Long.parseLong(id));
    }


    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "AudTrail: " + audTrailRecId + ", Status=" + recStaTypeCd;
    }

}

DAOImpl:

public List<AudTrailBean> getRcvFeederSysid(String rcvFeederSysId)
{
    return  sessionFactory.getCurrentSession().createQuery("from AudTrailBean where rcvFeederSysId='GRF'").list();
}

SQL日志

使用外部数据库客户端可以很好地使用此SQL。

Hibernate: select audtrailbe0_.AUD_TRAIL_REC_ID as AUD1_8_,
audtrailbe0_.AUD_TRAIL_REC_2_ID as AUD2_8_, audtrailbe0_.CORRL_ID as CORRL3_8_, audtrailbe0_.JAVA_MESSAGING_SRVC_TS as JAVA4_8_,
audtrailbe0_.MSG_POLLING_TS as MSG5_8_, audtrailbe0_.RCV_COMMUN_ID as
RCV6_8_, audtrailbe0_.RCV_FEEDER_SYS_ID as RCV7_8_,
audtrailbe0_.RCV_TMPLT_ID as RCV8_8_, audtrailbe0_.REC_STA_TYPE_CD as REC9_8_, audtrailbe0_.THUNDERHEAD_CALL_TS as THUNDER10_8_ 
from aud_trail audtrailbe0_ where audtrailbe0_.RCV_FEEDER_SYS_ID='GRF'

如果我执行代码意味着它将抛出以下错误。

root cause

org.hibernate.exception.SQLGrammarException: could not execute query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.loader.Loader.doList(Loader.java:2216)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    org.hibernate.loader.Loader.list(Loader.java:2099)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    com.gcs.dao.AudTrailDaoImpl.getRcvFeederSysid(AudTrailDaoImpl.java:30)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    com.sun.proxy.$Proxy60.getRcvFeederSysid(Unknown Source)
    com.gcs.service.AudTrailServiceImpl.getRcvFeederSysid(AudTrailServiceImpl.java:28)
    com.gcs.controller.TestSuitController.existingsystem(TestSuitController.java:93)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=TGXPR01.AUD_TRAIL, DRIVER=3.62.56
    com.ibm.db2.jcc.am.fd.a(fd.java:676)
    com.ibm.db2.jcc.am.fd.a(fd.java:60)
    com.ibm.db2.jcc.am.fd.a(fd.java:127)
    com.ibm.db2.jcc.am.jn.c(jn.java:2614)
    com.ibm.db2.jcc.am.jn.d(jn.java:2602)
    com.ibm.db2.jcc.am.jn.a(jn.java:2094)
    com.ibm.db2.jcc.am.kn.a(kn.java:6720)
    com.ibm.db2.jcc.t4.cb.g(cb.java:141)
    com.ibm.db2.jcc.t4.cb.a(cb.java:41)
    com.ibm.db2.jcc.t4.q.a(q.java:32)
    com.ibm.db2.jcc.t4.rb.i(rb.java:135)
    com.ibm.db2.jcc.am.jn.gb(jn.java:2064)
    com.ibm.db2.jcc.am.kn.pc(kn.java:3214)
    com.ibm.db2.jcc.am.kn.b(kn.java:3999)
    com.ibm.db2.jcc.am.kn.cc(kn.java:709)
    com.ibm.db2.jcc.am.kn.executeQuery(kn.java:683)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    org.hibernate.loader.Loader.doQuery(Loader.java:674)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    org.hibernate.loader.Loader.doList(Loader.java:2213)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    org.hibernate.loader.Loader.list(Loader.java:2099)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    com.gcs.dao.AudTrailDaoImpl.getRcvFeederSysid(AudTrailDaoImpl.java:30)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    com.sun.proxy.$Proxy60.getRcvFeederSysid(Unknown Source)
    com.gcs.service.AudTrailServiceImpl.getRcvFeederSysid(AudTrailServiceImpl.java:28)
    com.gcs.controller.TestSuitController.existingsystem(TestSuitController.java:93)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

我希望有人能帮助我找到解决方案。感谢。

0 个答案:

没有答案