Skip to content

Latest commit

 

History

History

HibernateSpringBootDtoResultTransformer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

How To Fetch DTO Via ResultTransformer And Native SQL

Description: Fetching more data than needed is prone to performance penalties. Using DTO allows us to extract only the needed data. In this application we rely on Hibernate, ResultTransformer and native SQL.

Key points:

  • use AliasToBeanConstructorResultTransformer for DTO without setters, but with constructor
  • use Transformers.aliasToBean() for DTO with setters
  • use EntityManager.createNativeQuery() and unwrap(org.hibernate.query.NativeQuery.class)
  • starting with Hibernate 5.2, ResultTransformer is deprecated, but until a replacement will be available (probably in Hibernate 6.0) it can be used (read further)
  • for using Spring Data Projections check this recipe

If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.