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

后端 未结 21 1784
孤街浪徒
孤街浪徒 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:46

    if you are using Spring, you can use org.springframework.jdbc.core.RowMapper

    Here is an example:

    public List query(String objectType, String namedQuery)
    {
      String rowMapper = objectType + "RowMapper";
      // then by reflection you can instantiate and use. The RowMapper classes need to follow the naming specific convention to follow such implementation.
    } 
    

提交回复
热议问题