JPQL查询 - 如何访问列表

时间:2013-04-18 12:21:43

标签: hibernate jpa jpql

我正在使用jpql。

但我在创建查询时遇到问题,因为“tgDeclarationRglts”是一个“列表”。

如何在查询中访问此列表以检索“idDeclarationRglt”?

谢谢!

“DeclarationRglt”实体

@Id
@SequenceGenerator(name="DECREG_IDDECLARATION_RGLT", sequenceName="SID_DECLARATION_RGLT" , allocationSize = 1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DECREG_IDDECLARATION_RGLT")
@Column(name="ID_DECLARATION_RGLT")
private long idDeclarationRglt;

“LigneDipRec”实体

//bi-directional many-to-many association to TgDeclarationRglt
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
    name="TG_DIP_RECOUVREMENT"
    , joinColumns={
        @JoinColumn(name="ID_LIGNE_DIP_REC")
        }
    , inverseJoinColumns={
        @JoinColumn(name="ID_DECLARATION_RGLT")
        }
    )
private List<DeclarationRglt> tgDeclarationRglts;

这是我的问题:

select distinct ta3.idTitre from LigneTa3 ta3, DeclarationRglt dec where ta3.tgDeclarationRglt.idDeclarationRglt =:idDecReg and dec.tcTypeDeclarationRglt.cdTypeDeclaration =:typeDec

1 个答案:

答案 0 :(得分:0)

由于您的查询使用了一个名为LigneTa3的实体,因此很难理解您的问题。

如果我纯粹看你问题的这一部分:

  

如何在查询中访问此列表以检索   “idDeclarationRglt”?

然后我认为您正在寻找的所有东西都基于:

SELECT d.idDeclarationRglt
FROM LigneDipRec l JOIN l.tgDeclarationRglts d

这显示了访问集合中每个元素的一般方法,您总是可以在更大的查询中使用该方法。