Join Queries & DTO Projection
Learn Join Queries & DTO Projection (Spring Data JPA, Spring Boot) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Two-Table Join Operation Business requirement: you have two tables and want to fetch data from both. In that case we go with the join approach. Problem statement: design the REST API to return this response, built from two tables: empDept • empDeptDesc • empName • empEmail • empAddress Table structure Notice that the five fields we want come from both tables and match neither entity. That is what a DTO is for: a class shaped like the answer rather than like a table.
More lessons in Spring Data JPA
- ORM, JPA and Hibernate
- Spring Data JPA
- Entity Mapping: @Entity, @Table, @Id, @Column
- Derived Query Methods - Fetch by Single & Multiple Fields
- JPQL and @Modifying Queries
- Native Query with @Query
- Mapping - Real-World Scenarios
- Mapping - One-to-One & One-to-Many
- Mapping - Many-to-One & Many-to-Many
- Cascade Types and orphanRemoval
- JPA Advanced - Auditing, Locking & Specifications
- Mini Project: Student Repository with Spring Data JPA