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

Google Search Rating Volatility, Wild AI Mode, Google Adverts Business Queries & Channel Reporting & ChatGPT Purchasing Search

Google Search Rating Volatility, Wild AI Mode, Google Adverts Business Queries & Channel Reporting & ChatGPT Purchasing Search

May 4, 2025
Meet LangGraph Multi-Agent Swarm: A Python Library for Creating Swarm-Model Multi-Agent Techniques Utilizing LangGraph

Meet LangGraph Multi-Agent Swarm: A Python Library for Creating Swarm-Model Multi-Agent Techniques Utilizing LangGraph

May 16, 2025

Trending.

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
ManageEngine Trade Reporter Plus Vulnerability Allows Distant Code Execution

ManageEngine Trade Reporter Plus Vulnerability Allows Distant Code Execution

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

Expedition 33 Guides, Codex, and Construct Planner

April 26, 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
7 Finest EOR Platforms for Software program Firms in 2025

7 Finest EOR Platforms for Software program Firms in 2025

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

Information temporary: AI safety dangers highlighted at RSAC 2025

Black Hat 2025: Navigating AI and provide chain safety

August 3, 2025
Credulous

Films, books and work | Seth’s Weblog

August 3, 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