org.hibernate.hql.internal.ast.QuerySyntaxException:路径无效:'1.id'

时间:2014-05-19 13:19:42

标签: java-ee jpa hql

我收到此错误,但我无法弄清楚原因?任何人都可以帮助我PLZ;

档案:AnnonceDao.java

public List<AnnonceColocation> listeAnnonceColocation( UserEntity idUser ) {
    Query query = getEntityManger()
            .createQuery(
                    "from AnnonceColocation, Annonce where AnnonceColocation.id = Annonce.id and Annonce.annonceUser= :idUser" )
            .setParameter( "idUser", idUser );
    List<AnnonceColocation> annonceColocation = (List) query.getResultList();
    return annonceColocation;
}

档案:Annonce.java

@Entity
@Table( name = "annonce" )
@Inheritance( strategy = InheritanceType.JOINED )
public class Annonce extends BaseEntity {

// attribut
// getter&setter

  }

文件:AnnonceColocation.java

    @Entity
    @Table( name = "annonceColocation" )
    @PrimaryKeyJoinColumn( name = "ID" )
    public class AnnonceColocation extends Annonce {

          // attribut 
          // getter/setter
     }

1 个答案:

答案 0 :(得分:9)

为每个实体分配别名,并在查询中使用这些别名:

from AnnonceColocation ac, Annonce a where ac.id = a.id and a.annonceUser= :idUser

此外,此查询显示您正在使用其他实体的ID,而不是使用实体之间的关联。这将使许多查询无法表达,并将阻止您轻松导航到实体图。阅读文档中关于关联的章节,并使用它们。