gpt4 book ai didi

jakarta-ee - org.hibernate.hql.internal.ast.QuerySyntaxException : Invalid path: '1.id'

转载 作者:行者123 更新时间:2023-12-05 08:24:07 24 4
gpt4 key购买 nike

我收到此错误,但我无法找出原因?任何人都可以帮助我吗?

文件: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
}

最佳答案

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

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

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

关于jakarta-ee - org.hibernate.hql.internal.ast.QuerySyntaxException : Invalid path: '1.id' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23738869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com