现在做项目的时候,碰到了一个问题,请帮忙看看怎么会事吧,谢谢了先~~
1)映射文件:
column="FIRST_NAME"
type="string"
length="40"
not-null="true"
/>
column="LAST_NAME"
type="string"
length="40"
not-null="true"
/>
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.
at org.hibernate.engine.query.HQLQueryPlan.
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.
at org.hibernate.engine.query.HQLQueryPlan.
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'