この文字列があると仮定します (これは JPQL クエリです - テーブル名と列名はエンティティ クラスを使用して正しく置換されます)
//The actual string is auto-generated, but this is just an example:
String sql =
"select la.laNo,la.status " +
"from LA la " +
"where (la.cc,la.laNo) in (" +
"select lap.cc,lap.laNo " +
"from LAP lap " +
"where lap.paNo = '145'" +
")";
私がやろうとすると:
Query q = org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(sql);
例外が発生します(簡潔にするために、いくつかの行が削除されています):
Exception Description: Syntax error parsing the query [select la.laNo,la.status from LA la where (la.cc,la.laNo) in (select lap.cc,lap.laNo from LAP lap where lap.paNo = '145')], line 1, column 48: syntax error at [,].
Internal Exception: MismatchedTokenException(81!=84)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1375)
Caused by: Exception [EclipseLink-8024] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.JPQLException
Internal Exception: MismatchedTokenException(81!=84)
at org.eclipse.persistence.exceptions.JPQLException.syntaxErrorAt(JPQLException.java:362)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:301)
...at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:17303)
...at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:130)
...at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:207)
...at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:134)
...at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1373)
... 13 more
Caused by: MismatchedTokenException(81!=84)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.mismatch(Unknown Source)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.match(Unknown Source)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:17279)
... 32 more
SQL は構文的に正しく、データベース マネージャーで実行すると正しく結果を返すことができます。では、どこに問題があるのでしょうか。
更新:
いくつかのテストを行ったところ、明らかに、これは機能します:
String sql =
"select la.laNo,la.status " +
"from LA la " +
"where la.cc in (" +
"select lap.cc " +
"from LAP lap " +
"where lap.paNo = '145'" +
") " +
"and la.laNo in (" +
"select lap1.laNo " +
"from LAP lap1 " +
"where lap1.paNo = '145'" +
")";
複数の列を選択しないのはなぜですか?