论坛首页 Java企业应用论坛

数据库Sybase 用hibernate里的hql语句不能正确解析?

浏览 3297 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-12-30  
数据库Sybase 用hibernate里的hql语句不能正确解析?
环境:
Hibernate2
Jdbc:com.sybase.jdbc3.jdbc.SybDataSource
状态:
在hibernate或者spring的template用load/delete/update都可以正常执行唯独用有带条件的hql语句来查询时候会提示条件foreignId解析出错,没有带条件则会正常执行
----------------------------代码
Query query = session.createQuery("from UserRight where foreignId=?");
query.setString(0,"1");
List list = query.list();
assertEquals(3,list.size());
---------------------------异常信息:
net.sf.hibernate.exception.GenericJDBCException: Could not execute query
at net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:80)
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at hibernate.HibernateDaoTestCase.testAddRightInfo(HibernateDaoTestCase.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: Invalid column name 'foreignId'.

at com.sybase.jdbc3.tds.Tds.processEed(Tds.java:3069)
at com.sybase.jdbc3.tds.Tds.nextResult(Tds.java:2373)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc3.jdbc.SybStatement.queryLoop(SybStatement.java:1705)
at com.sybase.jdbc3.jdbc.SybStatement.executeQuery(SybStatement.java:1690)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:92)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
... 17 more

-----------------配置文件
    <class name="UserRight" table="t_userRight">
        <id name="id" column="id" type="java.lang.Long">
            <generator class="native"/>
        </id>

        <property name="state" column="state" type="java.lang.Long" />
        <property name="foreignId" column="userId" type="java.lang.String" />
        <property name="inputdate" column="inputDate" type="java.util.Date" />
        <property name="version" column="version" type="java.lang.String" />
<property name="rightId" column="rightId"
type="java.lang.Long" />
    </class>
---------------javabean getter/setter自动生成的
private java.lang.Long id;
private java.lang.Long state;
private java.lang.String foreignId;
private java.util.Date inputdate;
private java.lang.String version;
private Long rightId;
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics