回 帖 发 新 帖 刷新版面

主题:eclipse下hibernate的Java.lang.IllegalStateException

Callerno,Calleeid,StartTime,EndTime这几项是我表XgsxCallLog里的字段
除了这几项以为我还需要一项DATEDIFF(s,StartTime,EndTime) as offset
offset不是我表的字段
当我用String hql = "FROM XgsxCallLog WHERE Callerno=?";这个hql语句
的时候不会出现错误.内容可以正常输出,在jsp页面我是这样写的
<table border="0" width="100%">
   <tr>
    <td>
     用户号码
    </td>
    <td>
     被叫号码
    </td>
    <td>
     开始时间
    </td>
   </tr>
   <logic:iterate id="numall" name="numall" scope="request">
    <tr>
     <td>
      ${numall.callerno}
     </td>
     <td>
      ${numall.calleeid}
     </td>
     <td>
      ${numall.startTime}
     </td>
    </tr>
   </logic:iterate>
</table>
可是当我用这条语句的时候便出现了错误
SELECT Callerno,Calleeid,StartTime,EndTime,DATEDIFF(s,StartTime,EndTime) as offset FROM XgsxCallLog WHERE Callerno=? 
这是为什么?sprint+hibername+struts


java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.Id
entNode
 +-[IDENT] IdentNode: 'Callerno' {originalText=Callerno}
        at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(Sel
ectClause.java:136)
        at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:
440)
        at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:351
)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.
java:126)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:
471)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWa
lker.java:201)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.j
ava:151)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl
.java:189)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorIm
pl.java:130)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl
.java:83)
        at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.jav
a:427)
        at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at org.jzk.fx.dao.impl.IXgsx_Call_LogDAOImpl.queryNUMAll(IXgsx_Call_LogD
AOImpl.java:20)
        at org.jzk.fx.struts.action.Xgsx_Call_LogAction.seltelnum(Xgsx_Call_LogA
ction.java:62)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchActio
n.java:274)
        at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:
194)
        at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:119
4)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
        at org.jzk.fx.filter.EncodingFilter.doFilter(EncodingFilter.java:22)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:186)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:793)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:702)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:571)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:644)
        at java.lang.Thread.run(Thread.java:595)

回复列表 (共3个回复)

沙发

XgsxCallLog.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="org.jzk.fx.vo.XgsxCallLog" table="xgsx_Call_Log" schema="dbo" catalog="tongli">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity"></generator>
        </id>
        <property name="callerno" type="java.lang.String">
            <column name="Callerno" length="50" />
        </property>
        <property name="calleeid" type="java.lang.String">
            <column name="Calleeid" length="50" />
        </property>
        <property name="userid" type="java.lang.String">
            <column name="userid" length="50" />
        </property>
        <property name="channo" type="java.lang.Integer">
            <column name="Channo" />
        </property>
        <property name="startTime" type="java.util.Date">
            <column name="StartTime" length="23" />
        </property>
        <property name="endTime" type="java.util.Date">
            <column name="EndTime" length="23" />
        </property>
        <property name="chatroomid" type="java.lang.Integer">
            <column name="chatroomid" />
        </property>
        <property name="sumhe" type="java.lang.Integer">
            <column name="sumhe" />
        </property>
    </class>
</hibernate-mapping>



板凳

没人知道吗

3 楼

不能用SQL语句,只能用HQL

我来回复

您尚未登录,请登录后再回复。点此登录或注册