大家好!
现在做项目的时候,碰到了一个问题,请帮忙看看怎么会事吧,谢谢了先~~
1)映射文件:
<hibernate-mapping >
<class name="Employee" table="EMPLOYEE">
<composite-id name="Id" class="EmployeePK">
<key-property name="BusinessUnitId" column="BUSINESS_UNIT_ID" type="string" length="2" />
<key-property name="EmployeeId" column="EMPLOYEE_ID" type="string" length="10"/>
</composite-id>
<property
name="FirstName"
column="FIRST_NAME"
type="string"
length="40"
not-null="true"
/>
<property
name="LastName"
column="LAST_NAME"
type="string"
length="40"
not-null="true"
/>
</class>
</hibernate-mapping>
2)代码:
String s = "select x.FirstName,x.LastName from (select x.FirstName,x.LastName from Employee x)";
List list = this.getSession().createQuery(s).list();
当然了,那个子查询里面还有n多条件,为了方便大家找原因,我把条件去掉了。即使加上那些条件,还是一样的错误。
3)错误信息:
2006-11-20 19:52:09,100 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - parse() - HQL: select x.FirstName,x.LastName from( select x.FirstName,x.LastName from Employee x)
2006-11-20 19:52:09,100 ERROR [org.hibernate.hql.PARSER] - line 1:36: unexpected token: (
2006-11-20 19:52:09,100 DEBUG [org.hibernate.hql.ast.ErrorCounter] - line 1:36: unexpected token: (
line 1:36: unexpected token: (
at org.hibernate.hql.antlr.HqlBaseParser.fromRange(HqlBaseParser.java:1584)
at org.hibernate.hql.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1408)
at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1130)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:248)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.pei.webpdm.itma.dao.hibernate.LabelImpl.getDivisionLabelList(LabelImpl.java:60)
at com.pei.webpdm.itma.dao.TestILabelDao.testgetDivisionLabelList(TestILabelDao.java:48)
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 org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
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 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2006-11-20 19:52:09,100 ERROR [org.hibernate.hql.PARSER] - line 1:69: unexpected token: from
2006-11-20 19:52:09,100 DEBUG [org.hibernate.hql.ast.ErrorCounter] - line 1:69: unexpected token: from
line 1:69: unexpected token: from
at org.hibernate.hql.antlr.HqlBaseParser.fromClassOrOuterQueryPath(HqlBaseParser.java:1909)
at org.hibernate.hql.antlr.HqlBaseParser.fromRange(HqlBaseParser.java:1564)
at org.hibernate.hql.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1428)
at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1130)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:248)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.pei.webpdm.itma.dao.hibernate.LabelImpl.getDivisionLabelList(LabelImpl.java:60)
at com.pei.webpdm.itma.dao.TestILabelDao.testgetDivisionLabelList(TestILabelDao.java:48)
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 org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
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 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2006-11-20 19:52:09,116 DEBUG [org.hibernate.hql.ast.AST] - --- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
+-[FROM] 'from'
\-[SELECT] 'select'
+-[DOT] '.'
| +-[IDENT] 'x'
| \-[IDENT] 'FirstName'
\-[DOT] '.'
+-[IDENT] 'x'
\-[IDENT] 'LastName'
分享到:
相关推荐
hql模糊查询hql模糊查询hql模糊查询hql模糊查询
Hibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询....
hibernate查询之HQLhibernate查询之HQLhibernate查询之HQL
hql多表查询hql多表查询hql多表查询
Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Lanaguage)查询提供了更加丰富的和灵活的查询特性,因此Hibernate将HQL查询方式立为官方推荐的标准查询方式,HQL查询...
HQL多表查询
Hibernate中的关联查询实际上生成的是数据库表连接查询的SQL语句
hibernate hql各类查询范例
HQL查询 帮助文档
HQL查询及语法,java web开发必备。
NHibernate HQL 条件查询
hql精点查询语句.doc
1、掌握Hibernate框架应用项目 2、学习HQL参数查询和Criteria查询 3、比较HQL和Criteria的不同 建立web项目,通过页面查询构造动态查询语句,struts2和hibernate框架整合。
HQL查询语言基础,HQL查询语言基础,HQL查询语言基础
HQL是指定连接查询方式,而且显式指定了关联级别的查询策略
HQL查询语言基础.
HQL语句查询
Spring中常用的hql查询方法_(getHibernateTemplate())
SSH笔记-HQL查询(基于位置参数查询、基于命名参数查询、分页查询、命名查询、投影查询报表查询、内/迫切内/左外/迫切左外连接查询)、QBC(QBC检索查询、统计查询、排序查询、HQL操作数据库)、本地SQL查询
HQL快速入门的好资料,先看看此资料,在有手册就差不多了。