xiaowanggedege 2006-12-30
数据库Sybase用hibernate里的hql语句不能正确解析?
环境:
Hibernate2
Jdbc:com.sybase.jdbc3.jdbc.SybDataSource
状态:
在hibernate或者spring的template用load/delete/update都可以正常执行唯独用有带条件的hql语句来查询时候会提示条件foreignId解析出错,没有带条件则会正常执行
----------------------------代码
Queryquery=session.createQuery("fromUserRightwhereforeignId=?");
query.setString(0,"1");
Listlist=query.list();
assertEquals(3,list.size());
---------------------------异常信息:
net.sf.hibernate.exception.GenericJDBCException:Couldnotexecutequery
atnet.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:80)
atnet.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
atnet.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
atnet.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
atnet.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
atnet.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
athibernate.HibernateDaoTestCase.testAddRightInfo(HibernateDaoTestCase.java:50)
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
atjava.lang.reflect.Method.invoke(Method.java:585)
atjunit.framework.TestCase.runTest(TestCase.java:154)
atjunit.framework.TestCase.runBare(TestCase.java:127)
atjunit.framework.TestResult$1.protect(TestResult.java:106)
atjunit.framework.TestResult.runProtected(TestResult.java:124)
atjunit.framework.TestResult.run(TestResult.java:109)
atjunit.framework.TestCase.run(TestCase.java:118)
atjunit.framework.TestSuite.runTest(TestSuite.java:208)
atjunit.framework.TestSuite.run(TestSuite.java:203)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Causedby:com.sybase.jdbc3.jdbc.SybSQLException:Invalidcolumnname'foreignId'.
atcom.sybase.jdbc3.tds.Tds.processEed(Tds.java:3069)
atcom.sybase.jdbc3.tds.Tds.nextResult(Tds.java:2373)
atcom.sybase.jdbc3.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
atcom.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:220)
atcom.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:203)
atcom.sybase.jdbc3.jdbc.SybStatement.queryLoop(SybStatement.java:1705)
atcom.sybase.jdbc3.jdbc.SybStatement.executeQuery(SybStatement.java:1690)
atcom.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:92)
atnet.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
atnet.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
atnet.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
atnet.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
atnet.sf.hibernate.loader.Loader.doList(Loader.java:1063)
atnet.sf.hibernate.loader.Loader.list(Loader.java:1054)
atnet.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
atnet.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
...17more
-----------------配置文件
<classname="UserRight"table="t_userRight">
<idname="id"column="id"type="java.lang.Long">
<generatorclass="native"/>
</id>
<propertyname="state"column="state"type="java.lang.Long"/>
<propertyname="foreignId"column="userId"type="java.lang.String"/>
<propertyname="inputdate"column="inputDate"type="java.util.Date"/>
<propertyname="version"column="version"type="java.lang.String"/>
<propertyname="rightId"column="rightId"
type="java.lang.Long"/>
</class>
---------------javabeangetter/setter自动生成的
privatejava.lang.Longid;
privatejava.lang.Longstate;
privatejava.lang.StringforeignId;
privatejava.util.Dateinputdate;
privatejava.lang.Stringversion;
privateLongrightId;