JPA : How to convert a native query result set to POJO class collection

后端 未结 21 1763
孤街浪徒
孤街浪徒 2020-11-22 09:23

I am using JPA in my project.

I came to a query in which I need to make join operation on five tables. So I created a native query which returns five fields.

21条回答
  •  遥遥无期
    2020-11-22 09:44

    JPA provides an SqlResultSetMapping that allows you to map whatever returns from your native query into an Entity or a custom class.

    EDIT JPA 1.0 does not allow mapping to non-entity classes. Only in JPA 2.1 a ConstructorResult has been added to map return values a java class.

    Also, for OP's problem with getting count it should be enough to define a result set mapping with a single ColumnResult

提交回复
热议问题