JPA Data Repositories with SqlResultSetMapping and native queries

前端 未结 3 2012
梦如初夏
梦如初夏 2020-12-16 14:19

I was stuck with the following situation:

My entities are related to each other, but in such a way that i could not use JPQL. I was forced to use native SQL. Now I w

3条回答
  •  悲&欢浪女
    2020-12-16 15:16

    You are almost there, but for the below parts

    1. The whole @SqlResultSetMapping and @NamedNativeQuery has to be present in the Entity and not the value Object. In your case it should be in the MyEntity class and **not ** the MyVO class. This should resolve your exception.
    2. That will still not do. After you do the above, change the below

      @NamedNativeQuery(name = "findAllDataMapping", to
      @NamedNativeQuery(name = "MyEntity.findAllDataMapping",

    3. Finally, in some cases you need to be explicit in your definition of @ColumnResult(name = "userFirstName"). If it is a complex field like ZonedDateTime or Boolean you may have to explicity state @ColumnResult(name = "date_created", type = ZonedDateTime.class).

    Hope that helps.

提交回复
热议问题