我收到此错误,但我无法弄清楚原因?任何人都可以帮助我PLZ;
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;
}
@Entity
@Table( name = "annonce" )
@Inheritance( strategy = InheritanceType.JOINED )
public class Annonce extends BaseEntity {
// attribut
// getter&setter
}
@Entity
@Table( name = "annonceColocation" )
@PrimaryKeyJoinColumn( name = "ID" )
public class AnnonceColocation extends Annonce {
// attribut
// getter/setter
}
答案 0 :(得分:9)
为每个实体分配别名,并在查询中使用这些别名:
from AnnonceColocation ac, Annonce a where ac.id = a.id and a.annonceUser= :idUser
此外,此查询显示您正在使用其他实体的ID,而不是使用实体之间的关联。这将使许多查询无法表达,并将阻止您轻松导航到实体图。阅读文档中关于关联的章节,并使用它们。