Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • I was need to retrieve plain POJO not entity. I tried your approach without success. Anyway I solved this, see answer :) Commented Feb 1, 2015 at 11:34
  • 4
    you misunderstood my answer. With my approach, you are still retrieving plain POJO (AggregateStatsDto), just that you need to put the SqlResultSetMapping annotation into some other class which is an Entity for the entity manager to recognize it. Commented Feb 2, 2015 at 14:44
  • 2
    It is really annoying that JPA expects us to create this intermeidate entity class to return an adhoc query thi sway... Commented Jun 15, 2021 at 18:38
  • This presumes that you have an entity for your queried table. But what if you query against a view, which is a join of multiple tables, that are not tracked by hibernate? Commented Jan 4, 2022 at 9:15
  • No. All we are doing is putting the SqlResultSetMapping annotation into some arbitrary Java class that is annotated as an Entity. Said entity is not part of your query, but just uses as the medium to make JPA aware of the defined mapping. Commented Jan 4, 2022 at 22:16