How to retrieve only certain fields of an entity in JPQL or HQL? What is the equivalent of ResultSet in JPQL or HQL?

后端 未结 4 813
名媛妹妹
名媛妹妹 2020-12-14 02:02

In JPQL, I can retrieve entities by :

query = entityManager.createQuery(\"select c from Category c\");
List categories = query.getResultList(         


        
4条回答
  •  不思量自难忘°
    2020-12-14 02:39

    It is not the use of the .list() function itself which makes the result a List. It is the specification of fields (c.id, c.name) in the HQL query. If your query is

        "select c from Category c"
    

    Then query.list() will return a List object.

提交回复
热议问题