Quite often JPQL is not powerful enough to perform the queries you need in real world projects. In general, this is not an issue because JPA is designed as a leaky abstraction and you can use the full potential of SQL by using native queries.
The only downside is, that these queries return a List of Object[] instead of the mapped entities and value objects you are used to get from JPQL queries.
Each Object[] in the List contains one record returned by the database. You then need to iterate through the array, cast each Object to its specific type and map them to your domain model. This creates lots of repetitive code and type casts.
It would be more comfortable, if you could tell the EntityManager to map the result of the query into entities or value objects as it is the case for JPQL statements. The good news is, JPA provides this functionality. It is called SQL result set mapping and in this video, I will show you how to use it to map your query results to managed entities.
If you like this video, please give it a thumbs up and share it with your friends and co-workers.
Like my channel? Subscribe!
➜ http://bit.ly/2cUsid8
Join the free Member Library:
https://goo.gl/dtyIIC
Read the accompanying post: http://www.thoughts-on-java.org/resul...
Want to connect with me?
Blog: http://www.thoughts-on-java.org/
Twitter: / thjanssen123
Facebook: / thoughtsonjava
#JPA #Hibernate #SQL #EntityManager #JPQL
On this page of the site you can watch the video online JPA & Hibernate: Basic result set mappings for native SQL queries with a duration of hours minute second in good quality, which was uploaded by the user Thorben Janssen 22 February 2017, share the link with friends and acquaintances, this video has already been watched 13,693 times on youtube and it was liked by 138 viewers. Enjoy your viewing!