How to Return DTOs from Native Queries with Spring Data JPA

preview_player
Показать описание
When using Spring Data JPA, you are used to derived and custom queries that return the result in your preferred format. A typical example is a DTO projection, which is the most efficient one for read-only operations. To use it in a derived or custom JPQL query, you only need to change the return type of your repository method to your DTO class or interface. But when using a native query, some limitations make DTOs a little harder to use.

Links mentioned:
Result Set Mapping: Constructor Result Mappings

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?

#SpringDataJPA #ReturnDTOs #NativeQuery
Рекомендации по теме
Комментарии
Автор

I was getting this ConverterNotFoundException, searched alot about this but didn't find anything specific. Found this video which is extremely helpful

rohanbipetkar
Автор

This tutorial is super concise and accurate. It accurately answered the questions most likely to be asked by fresh learners like me..

haoxu
Автор

wao I did save a lot of time just doing the first scenario, making an interface for getting the data.
thanks a lot

kennedmena
Автор

Superb video !! Thanks a lot. This helped me a lot.

yousufbaig
Автор

This is the good things, but I didn't get how it works, I need to try it in ide. Maybe in next video if is possible to show how it works in IDE with real coding for better understanding 🤔

Denys.Stoianov
Автор

tell me when query gives you list of names then how to get that list?

ModifiedGaddiyan
Автор

Good Morning, I have a scenario to fetch the data from teradata sql views by using spring-boot-data-jpa with no primary key column in database.
1. When using entity it is expecting primary key but we don't have the PK ID column in database.

Existing behaviour of data mapping:
They joined multiple views and getting the data and mapping DTO class by using RowMapper with spring-boot < 3.x
Expected:
After >3.x spring-boot version upgrade data binding is not happening.

If you have any idea that would be great helpful to me?? Thanks

Note:I have done the all the code change related to JPA but getting the Exception like ID column not found in database because as mentioned don't have Id column in views..

srikanthkadiyala
Автор

Good content but it's complex. JPA can execute with native query to return the entity class. Then I can map the enity class to the dto.

profebuka
Автор

Hello, Can you please make a tuto or blog on - how to do the scalar projection? Got few lines in tour blog but not details implementation, I am talking about the object[ ] way to implement DTO

urrahman
Автор

If I use namednativequery with custom DTO using sqlresultsetmapping. Is it possible to perform pagination for that?

kushalyeluri
Автор

p.first_name as firstName. But what would be the alias for a nested object? For example, address.street as {what?} (assuming that PlayerName references Address)?

ekaterinagalkina
Автор

kkk, mais uma vez precisei assistir esse vídeo.

menssageiro
Автор

@Thorben Can I export these Repos as a Jar and use them in different projects?

KrishnaKishore
Автор

sorry, i fail with field id data type bigint sqlserver -> data type java Long. Exception: Could not locate appropriate constructor on class: xxxDto

TrinhNguyen-lfzp
Автор

Hi, Thorben, ich mag deine Videos sehr und habe normal auch kein Problem, diese in englischer Sprache zu hören, aber manchmal wäre es auch cool sie zusätzlich in deutsch anschauen zu können. vll. denkst du mal darüber nach auch deutsche Untertitel einzubauen. Mach Weiter so!

marcelbartholome
Автор

That's too much code.
Just use " select new MyPojo( a.col1, a.col2... ) from Table a"

ShinAkuma