【问题标题】:JPA/JPQL message error syntaxJPA/JPQL 消息错误语法
【发布时间】:2013-06-22 23:30:57
【问题描述】:

人!

我编写代码 JPA/HQL 并运行,但出现错误消息。说:

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [Select t.disciplina.nomeDisciplina, n.notaFinal From (Select f.notas as notas, sum(f.f1 + f.f2 + f.f3 +f.f4) as soma from Frequencia f group by f.notas) subquery inner join subquery.notas n inner join n.aluno1 a inner join n.turma1 t inner join a.usuario u where u = ?1], line 1, column 54: unexpected token [(].Internal Exception: org.eclipse.persistence.internal.jpa.parsing.jpql.InvalidIdentifierException 

我使用子句子查询创建 HQL(query),见下文。

 public List<Object[]> getListNotasFrequencia(Usuario u) {
        EntityManager em = getEntityManager();

        List<Object[]> lista = new Vector<Object[]>();

        String query = "Select t.disciplina.nomeDisciplina, n.notaFinal "
               + " From (Select f.notas as notas, sum(f.f1 + f.f2 + f.f3 +f.f4) as soma from Frequencia f group by f.notas) subquery  "
                + " inner join subquery.notas n"
                + " inner join n.aluno1 a"
                + " inner join n.turma1 t"
                + " inner join a.usuario u"
                + " where u = ?1"; 

        try {
            lista = em.createQuery(query).setParameter(1, u).getResultList();
        } finally {
            em.close();
        }
        return lista;
    }

我已经多次错误地处理此代码,但同样的错误消息。

请!您帮助或提示此代码。我开始学习这个 JPA/JPQL。

谢谢!!!

【问题讨论】:

    标签: java hibernate jakarta-ee jpa jpql


    【解决方案1】:

    问题是 FROM 子句中的子选择,JPA 不支持。 EclipseLink 确实对此提供了一定程度的支持,但是您继续从这个不存在的对象中为关系设置别名,所以我看不出您期望它如何工作。

    要么修改查询以仅使用普通连接,要么使用本机 SQL 查询。

    【讨论】:

      猜你喜欢
      • 2016-11-27
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2014-08-17
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多