Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:09:26+00:00 2026-06-06T05:09:26+00:00

JPQL queries can return custom result objects with the NEW operator: SELECT NEW myPackage.MyVO(e.fieldX,

  • 0

JPQL queries can return custom result objects with the NEW operator:

  SELECT NEW myPackage.MyVO(e.fieldX, e.relationshipX.fieldY)
  FROM MyEntity AS e

This is very useful to feed VOs. The problem is, you have to create constructors that exactly match the number of arguments, order and types of your query projection. This starts to get messy when you use a lot of projections for the same VO… Either you have one big constructor in your VO and resort to a lot of NULL literals on your query, or your VO must have a lot of different constructors.

So my question is: Is there a way in JPQL to set result object fields through mutators instead of constructors?

To people with .NET background, I’m looking to a equivalent of LINQ + object initializers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:09:28+00:00Added an answer on June 6, 2026 at 5:09 am

    DataNucleus JPA certainly supports two ways of instantiating result objects using no non-standard annotations or calls, primarily driven by the fact that it also supports JDO and that has the requirement for it :-

    1. Result type with argumented constructor (as you say)
    2. Result type with default constructor, and with setters

    Such as

    TypedQuery<MyResultType> q = em.createQuery("SELECT x AS field1, y AS field2 FROM ...", MyResultType.class);
    

    where MyResultType has setters “setField1”, “setField2”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPQL statement to return a schedule of sports games: SELECT NEW
Can I do something like this on JPQL? SELECT NEW com.MyDTO(p.a, p.b, q.c, q.d)
How can i write this sql in jpql syntax? SELECT SUM(t1.preise) FROM ( SELECT
In hibernate I want to run this JPQL / HQL query: select new org.test.userDTO(
i have four queries that return intergers. select listOfIntegers from [something]... ( edit: the
In JPQL what is escape character we can use to escape characters such as
I'm having trouble figuring out how to represent the following JPQL query: SELECT count(e)
I was trying to do something that apparently doesn't work in JPQL: JPQL: select
select x from X x where x.a.id = :a_id --> Always 0 objects selected
I'm trying the following JPQL and it fails misserably: Query query = em.createQuery(SELECT u

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.