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

  • Home
  • SEARCH
  • 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 8231063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:20:59+00:00 2026-06-07T17:20:59+00:00

I have two named queries, and both have the same logic, except that each

  • 0

I have two named queries, and both have the same logic, except that each one uses a different object constructor to select the results into

Named Query 1:

SELECT DISTINCT NEW dk.NewsRoomView(n,p)
FROM NewsItem n LEFT JOIN n.placements p JOIN n.actors a

Named Query 2:

SELECT DISTINCT NEW dk.NewsRoomView(n.id,n.title,SIZE(n.attachments),p.id,p.page)
FROM NewsItem n LEFT JOIN n.placements p JOIN n.actors a

The Structure of the NewsRoomView class

public class NewsRoomView{

  public NewsRoomView(NewsItem n, NewsItemPlacement p)
    Logger.getLogger(NewsRoomView.class.getName()).log(Level.INFO,"at Contsructor 1");
  }

  public NewsRoomView(Long id, String title, Integer attachments, Long pId, Integer page){
    Logger.getLogger(NewsRoomView.class.getName()).log(Level.INFO,"at Contsructor 2");
  }
}

Now whenever Named Query 1 gets executed it successfully prints the “at constructor 1” statement and thus the query returns results, but when Named Query 2 gets executed it neither prints out the statement “at Constructor 2”, nor returns results.

The code blocks above are only snippets of what I really have. In reality the second constructor has a 23 long argument list, that represents some more fields in the NewsItem and NewsItemPlacement entities.

I was wondering what could be wrong that prevents the second constructor from returning results, and whether there are limits on the size of the arguments list for the constructor.

Thanks in advance.

  • 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-07T17:21:01+00:00Added an answer on June 7, 2026 at 5:21 pm

    Because there is no exception thrown, it means that generated query was executed against database without problems, but query didn’t returned any rows. Problem has nothing to do with constructor expression and number of arguments.

    I guess that there is no such a NewsItem that have entry in attachment table. Such a rows will not be part of result set, because SIZE(n.attachments) causes id based inner join to attachments table. This all comes much more clear if you take a look to the generated SQL queries.

    Minimal example with same problem

    Entities

    @Entity
    public class EntityA {
        @GeneratedValue (strategy = GenerationType.TABLE)
        @Id public int id;
        @OneToMany(mappedBy = "a")
        public List<EntityB> bList;
         ...
    }
    
    @Entity
    public class EntityB {
        @GeneratedValue (strategy = GenerationType.TABLE)
        @Id
        public int id;
    
        @ManyToOne
        private EntityA a;
    }
    

    Database content

    EntityA
    |ID | 
    | 1 |
    | 2 |
    
    EntityB
    |ID |A_ID |
    | 1 |  2  |
    

    Query

    Query q = em.createQuery("Select SIZE(a.bList) FROM EntityA a");
    

    EclipseLink (2.3.2) with MySQL generates following SQL query:

    SELECT COUNT(t0.ID) FROM ENTITYB t0, ENTITYA t1 
    WHERE (t0.A_ID = t1.ID) GROUP BY t1.ID
    

    As you see, it returns size of bList only for such an EntityA that does have one or more entries in EntityB table.

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

Sidebar

Related Questions

I have two databases named: DB_A and DB_B . Each database has one collection
I have two .NET applications that talk to each other over a named pipe.
I have two tables, both named as say, Employee in two different schema HR
I have two complex rails (AR) queries coming from two different methods that I
I wrote two queries below that produce one row of data each. What is
Hi everyone I'm having a problem. I have two SQL queries that are both
I have two queries that I need to combine in LINQ that both actually
I have two linq queries that I run on two different tables, Car and
I have two tables table1 and table2 each having a column named email along
I have two very similar SQL queries that return a count of minutes spent

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.