我有一个DAO方法。
public ScrollableResults getPRecords(StatelessSession statelessSession) throws UnsupportedEncodingException{
Criteria crit = statelessSession.createCriteria(APRecord.class, "apr");
crit.createAlias("mAsset", "aId", Criteria.INNER_JOIN);
SQLQuery q=statelessSession.createSQLQuery("select distinct aId1_.aId, this_.pNAME, " +
"this_.kNum," +
"from " +
"AP_CPView " +
"this_ inner join A_MAView aId1_ " +
"on this_.agentG= aId1_.AgentG ");
return q.scroll(ScrollMode.FORWARD_ONLY);
}
查询在SQL中运行正常但是尝试在Hibernate中编写它会给我带来错误。
org.hibernate.exception.GenericJDBCException: could not execute query using scroll
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.scroll(Loader.java:2402)
at org.hibernate.loader.custom.CustomLoader.scroll(CustomLoader.java:322)
at org.hibernate.impl.StatelessSessionImpl.scrollCustomQuery(StatelessSessionImpl.java:626)
at org.hibernate.impl.AbstractSessionImpl.scroll(AbstractSessionImpl.java:170)
at org.hibernate.impl.SQLQueryImpl.scroll(SQLQueryImpl.java:205)
at com.test.hibernate.HibernateAcMDAOTest.getPatchRecords(HibernateAcMDAOTest.java:199)
at com.test.hibernate.HibernateAcMDAOTest.testFilteredPRecords(HibernateAcMDAOTest.java:344)
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:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at org.unitils.UnitilsJUnit3.runTest(UnitilsJUnit3.java:111)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.unitils.UnitilsJUnit3.runBare(UnitilsJUnit3.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'from'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.processOutput(MSCursorResultSet.java:943)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.cursorCreate(MSCursorResultSet.java:541)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.<init>(MSCursorResultSet.java:154)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:424)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
at org.hibernate.loader.Loader.scroll(Loader.java:2367)
... 27 more
我尝试过不同的东西,但最终却是错误的。有人能说出为什么来自我的错误吗?
答案 0 :(得分:0)
你有额外的昏迷。
更改此行:
<button class="button btn-custom button-full button-assertive icon icon-left ion-android-bicycle no-border red-custom no-margin">
<a href="#/category/sport"></a>
</button>
到
"this_.kNum," +