• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

The Second Finest Solution to Fetch a Spring Information JPA DTO Projection – Java, SQL and jOOQ.

Admin by Admin
May 16, 2025
Home Coding
Share on FacebookShare on Twitter


I’ve simply stumbled upon this nice submit by Vlad Mihalcea, titled The Finest Solution to Fetch a Spring Information JPA DTO Projection. It bought some good traction on reddit, too. That is such a pleasant use-case and apt resolution, I needed to rapidly present the second greatest means of doing the identical, with jOOQ this time.

Tip: you’ll be able to simply use jOOQ with Spring Information JPA, simply use Spring Boot’s jOOQ starter, inject the DataSource to jOOQ, then delegate all repository queries to jOOQ.

I’ll skip proper to the hierarchical DTO projection from the submit, which initiatives issues into this kind hierarchy:

public report PostCommentDTO (
    Lengthy id,
    String assessment
) {}

public report PostDTO (
    Lengthy id,
    String title,
    Listing feedback
) {}

So, we’ll be utilizing jOOQ like this utilizing the MULTISET worth constructor:

Listing end result =
ctx.choose(
        POST.ID,
        POST.TITLE,
        multiset(
            choose(POST_COMMENT.ID, POST_COMMENT.REVIEW)
            .from(POST_COMMENT)
            .the place(POST_COMMENT.POST_ID.eq(POST.ID))
        ).convertFrom(r -> r.map(mapping(PostCommentDTO::new)))
   )
   .from(POST)
   .the place(POST.TITLE.like(postTitle))
   .fetch(mapping(PostDTO::new));

Alternatively, use the MULTISET_AGG mixture operate, if that’s extra your factor (and in case you’re not nesting collections greater than 1 stage deep):

Listing end result =
ctx.choose(
        POST_COMMENT.submit().ID,
        POST_COMMENT.submit().TITLE,
        multisetAgg(POST_COMMENT.ID, POST_COMMENT.REVIEW)
            .convertFrom(r -> r.map(mapping(PostCommentDTO::new)))
   .from(POST_COMMENT)
   .the place(POST_COMMENT.submit().TITLE.like(postTitle))
   .fetch(mapping(PostDTO::new));

Each options are utterly sort protected, utilizing ad-hoc report conversion. You alter the schema, re-generate the code, and your code now not compiles.

Aside from the question itself, you don’t want to put in writing any extra infrastructure logic.

Cool, proper? 🙂

Like this:

Like Loading…

Tags: DataDTOFetchJavajOOQJPAProjectionSpringSQL
Admin

Admin

Next Post
Norman Reedus Open To Be In Demise Stranding Film If He is Requested

Norman Reedus Open To Be In Demise Stranding Film If He is Requested

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

10 Finest Cloud Price Administration Software program (2026): My Picks

10 Finest Cloud Price Administration Software program (2026): My Picks

February 2, 2026
“Be your self” | Seth’s Weblog

“GET OUTTA MY WAY”

August 24, 2025

Trending.

AI-Assisted Menace Actor Compromises 600+ FortiGate Gadgets in 55 Nations

AI-Assisted Menace Actor Compromises 600+ FortiGate Gadgets in 55 Nations

February 23, 2026
Introducing Sophos Endpoint for Legacy Platforms – Sophos Information

Introducing Sophos Endpoint for Legacy Platforms – Sophos Information

August 28, 2025
How Voice-Enabled NSFW AI Video Turbines Are Altering Roleplay Endlessly

How Voice-Enabled NSFW AI Video Turbines Are Altering Roleplay Endlessly

June 10, 2025
Rogue Planet’ in Growth for Launch on iOS, Android, Change, and Steam in 2025 – TouchArcade

Rogue Planet’ in Growth for Launch on iOS, Android, Change, and Steam in 2025 – TouchArcade

June 19, 2025
10 tricks to begin getting ready! • Yoast

10 tricks to begin getting ready! • Yoast

July 21, 2025

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Advertising experiments each progress workforce ought to run

Advertising experiments each progress workforce ought to run

February 26, 2026
Palantir indicators a cope with The Nuclear Firm beneath which the startup can pay Palantir $100M over 5 years to develop AI software program for the nuclear business (Miquela Thornton/Bloomberg)

New York’s AG sues Valve over its use of loot packing containers, accusing the sport developer of violating state playing legal guidelines and threatening to addict kids to playing (Jonathan Stempel/Reuters)

February 25, 2026
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved