• 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.

Artists push again in opposition to Barbie-like AI dolls with their very own creations

Artists push again in opposition to Barbie-like AI dolls with their very own creations

April 21, 2025
Fortnite Galactic Battle Begins Might 2 With New Occasion; Updates Incoming

Fortnite Galactic Battle Begins Might 2 With New Occasion; Updates Incoming

April 21, 2025

Trending.

Industrial-strength April Patch Tuesday covers 135 CVEs – Sophos Information

Industrial-strength April Patch Tuesday covers 135 CVEs – Sophos Information

April 10, 2025
Expedition 33 Guides, Codex, and Construct Planner

Expedition 33 Guides, Codex, and Construct Planner

April 26, 2025
How you can open the Antechamber and all lever places in Blue Prince

How you can open the Antechamber and all lever places in Blue Prince

April 14, 2025
Important SAP Exploit, AI-Powered Phishing, Main Breaches, New CVEs & Extra

Important SAP Exploit, AI-Powered Phishing, Main Breaches, New CVEs & Extra

April 28, 2025
Wormable AirPlay Flaws Allow Zero-Click on RCE on Apple Units by way of Public Wi-Fi

Wormable AirPlay Flaws Allow Zero-Click on RCE on Apple Units by way of Public Wi-Fi

May 5, 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

Borderlands 4 is a daring departure for the collection, however 2K could have carved off a few of its soul within the pursuit of killing cringe – preview

Borderlands 4 is a daring departure for the collection, however 2K could have carved off a few of its soul within the pursuit of killing cringe – preview

June 18, 2025
Coding a 3D Audio Visualizer with Three.js, GSAP & Internet Audio API

Coding a 3D Audio Visualizer with Three.js, GSAP & Internet Audio API

June 18, 2025
  • 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