我有以下在 SQL 软件 (HeidiSQL) 中完美运行的 SQL
SELECT gl2.documentNumber, gl2.debitAmount, gl2.creditAmount,
gl2.account, gl2.description FROM GeneralLedger AS gl1
LEFT JOIN GeneralLedger AS gl2
ON gl1.documentNumber = gl2.documentNumber
WHERE gl1.account='911' AND gl2.account <> '911';
何时将其放入 Play!控制器,我用这个:
String queryPL = "SELECT gl2.documentNumber, gl2.debitAmount, gl2.creditAmount, "
+ "gl2.account, gl2.description FROM GeneralLedger AS gl1 "
+ "LEFT JOIN GeneralLedger AS gl2 "
+ "ON gl1.documentNumber = gl2.documentNumber "
+ "WHERE gl1.account='911' AND gl2.account <> '911'";
Query query = JPA.em().createQuery(queryPL);
List<Object[]> profitAndLoss = query.getResultList();
并收到错误:
IllegalArgumentException 发生:org.hibernate.hql.ast.QuerySyntaxException:意外令牌:在第 1 行,第 156 列附近打开 [SELECT gl2.documentNumber,gl2.debitAmount,gl2.creditAmount,gl2.account,gl2.description FROM models.GeneralLedger AS gl1 LEFT JOIN GeneralLedger AS gl2 ON gl1.documentNumber = gl2.documentNumber WHERE gl1.account='911' AND gl2.account <> '911']
我将 HQL 修改为
String queryPL = "SELECT gl2.documentNumber, gl2.debitAmount, gl2.creditAmount, "
+ "gl2.account, gl2.description FROM models.GeneralLedger AS gl1 "
+ "LEFT OUTER JOIN models.GeneralLedger AS gl2 "
+ "WITH gl1.documentNumber = gl2.documentNumber "
+ "WHERE gl1.account='911' AND gl2.account <> '911'";
Query query = JPA.em().createQuery(queryPL);
List<Object[]> profitAndLoss = query.getResultList();
仍然收到错误:
发生 IllegalStateException:没有左侧的 DOT 节点!
那么我该如何解决这个问题呢?