我有StudentInfo类的studentinfo缓存和ClassInfo的classinfo缓存, 这两个类用于连接(Student具有classId的属性)
使用以下代码段
SqlFieldsQuery innerJoinSQL = new SqlFieldsQuery(
"select StudentInfo.studentId, StudentInfo.name, StudentInfo.classId from StudentInfo as a, " +
"\"class_cache\".ClassInfo as b where a.classId = b.classId");
cursor = studentCache.query(innerJoinSQL);
for (List data : cursor) {
System.out.println(String.format("studentId %s, studentName %s, classId %s, className %s", data.get(0), data.get(1), data.get(2), data.get(3)));
}
我遇到了以下异常:
Exception in thread "main" javax.cache.CacheException: Failed to parse query: select a.studentId, a.name, a.classId, b.name from StudentInfo a, 'class_cache'.ClassInfo b on a.classId = b.classId
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1137)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$2.applyx(GridQueryProcessor.java:732)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$2.applyx(GridQueryProcessor.java:730)
at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1666)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:730)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:700)
at ignite.sqlgrid.join.IgniteSQLJoinQueryTest.main(IgniteSQLJoinQueryTest.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SELECT A.STUDENTID, A.NAME, A.CLASSID, B.NAME FROM STUDENTINFO A, 'class_cache'[*].CLASSINFO B ON A.CLASSID = B.CLASSID "; expected "identifier"; SQL statement:
select a.studentId, a.name, a.classId, b.name from StudentInfo a, 'class_cache'.ClassInfo b on a.classId = b.classId [42001-191]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.getSyntaxError(DbException.java:205)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:3115)
at org.h2.command.Parser.readTableFilter(Parser.java:1202)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1884)
at org.h2.command.Parser.parseSelectSimple(Parser.java:2032)
at org.h2.command.Parser.parseSelectSub(Parser.java:1878)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1699)
at org.h2.command.Parser.parseSelect(Parser.java:1687)
at org.h2.command.Parser.parsePrepared(Parser.java:443)
at org.h2.command.Parser.parse(Parser.java:315)
at org.h2.command.Parser.parse(Parser.java:287)
at org.h2.command.Parser.prepareCommand(Parser.java:252)
at org.h2.engine.Session.prepareLocal(Session.java:560)
at org.h2.engine.Session.prepareCommand(Session.java:501)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:276)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatement(IgniteH2Indexing.java:406)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1121)
... 12 more
问题出在哪里可以提供帮助吗?谢谢!
答案 0 :(得分:-2)
看起来我发现了问题。
我的每个缓存的两个pojo(StudentInfo和ClassInfo)都有一个名为classId
的列。看起来只有一个pojo可以在classId字段
@QuerySqlField(index = true)
设置index = true
但我不确定Ingite是否有这样的约束。如果有人知道,请确认,谢谢!