ElementCollection createAlias in hibernate API

后端 未结 3 1686
北荒
北荒 2021-02-07 12:53

does anyone know if and how the solution for following question (which is written in the JPA API) can be written using the hibernate criteria API?

To be more specific I

3条回答
  •  名媛妹妹
    2021-02-07 13:24

    Late answer.

    The correct propertyName for collection (annotated by @ElementCollection) is "elements" or constant CollectionPropertyNames#COLLECTION_ELEMENTS.

    Try with the following answers

    Criteria crit = getSession().createCriteria(Discussion.class);
    crit.createAlias("participants", "p");
    
    crit.add(Restrictions.eq("p.elements", portalUsername));
    

    or use the constant COLLECTION_ELEMENTS instead

    crit.add(Restrictions.eq("p." + CollectionPropertyNames.COLLECTION_ELEMENTS, portalUsername));
    

提交回复
热议问题