Spring Data JPA: Query Projections

preview_player
Показать описание
The Projection is one of the first things you’re probably thinking about when implementing a query with Spring Data JPA. This is because projection defines the entity attributes and the database columns returned by your query. So, selecting the right columns is important for your business logic. At the same time, projection is also crucial for the performance of your application and the maintainability of your code. In addition, you need to choose a projection that keeps the overhead as low as possible and provides the data in an easy to use structure.
In this video, I will show you all the query projections supported by Spring Data JPA and which one you should use.

Links mentioned:

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?

#Spring #JPA #Query #Projections
Рекомендации по теме
Комментарии
Автор

Good day, @Thorben. I've been subscribed to your mailing list for a while and I've enjoyed your awesome content, especially with regards to Java Hibernate framework.

My first time being on the channel. I wish you the best.

I have committed to learning Spring framework + Hibernate framework by the end of this year or early next year. I have good practical knowledge of Java and
OOP design principles.

andromadusnaruto
Автор

That was great! I didn't know that spring could fetch entity properties in a DTO projection based on parameter names on the constructor! I always coded the constructor expression in the query...

sergiowwwat
Автор

You are the best, thanks for the information.

ronaldcastaneda
Автор

Great tutorial, Please tell me how to fetch child data by a certain field from parent using spring projections. Thanks. Subscribed!

cinemaismywife
Автор

Good video .. can u please do a lesson based on using Criteria Builder with associations (joins)

chiths
Автор

Great content, but how to use class dto for store procedure?

anjanx
Автор

Hey Thorben,

Thanks for your great video.
I see many people are using JDBC template for fetching DTO because it is highly customizable.
But I think JDBC template is easily messed up, and error-prone, and it is not readable when the query takes dynamic WHERE conditions.

Could you let us know there is any benefit to use JDBC template against Spring Projection when it comes to outbound DTO projection?

Thanks!

ebichu
Автор

Great tutorial, How can we populate interface projection from Json file for testing

gurugovindgarg
Автор

How to pass associate object in constructor in JPQL query. Just u have shown only passing properties not obj.

mukhirais
Автор

I'm using Interface projtion and one of the get method in interface of type OffsetDateaTime but it's giving error.. could you please shade some light on the issu

khairnarshekhar
Автор

Please tell me how to fetch child data by a certain field from parent using spring projections.

cinemaismywife
Автор

Is projection can me mixed with specification?

vinaykaushikinvisble
Автор

Good day @Thorben, i have a use case which i'm trying to glue graphql with jpa. The problem is queries from graphql are dynamic. They are then converted to JPA CriteriaQuery to generate projections and predicates to construct SQL. I need to map my resultset back to the JPA entity. I have tried AliasToBeanResultTransformer to auto-map my projections. I'm using hibernate beneath it. Unfortunately, I realised JPA CriteriaQuery converted to HQL is not producing aliases in the projection although I have configured aliases. This result in AliasToBeanResultTransformer not able to map the resultset back to the entity attributes. Do you have any reccomendation?

kennyng
Автор

When you need a class based DTO projection you can't use nested fields. There is no support for this out of the box.
If you want to get unmanaged entity with nested fields like Collection<Something> you'll have to resort to using tools like Mapstruct.
That was a real downside for me. Manageable but a downside non the less.

Quester