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 7431371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:17:07+00:00 2026-05-29T09:17:07+00:00

Hi Can anyone help me create a criteria base on the following information. Basically

  • 0

Hi Can anyone help me create a criteria base on the following information.
Basically this code will be added to a function that returns the number of found rows with
the number of child rows greater than 10. The value 10 will be dynamic.

I have been stuck with this problem for a day already and need some help.

Note that I can not control the database itself so I can not use views or change the database schema. Also this is a simplified version of the problem other properties of client and mapfields are omitted and the creation of the projections and criteria will be refactored to a generic helper method.

public class client
{
private int id;
private string code;
@OneToMany(fetch=FetchType.Lazy)
@JoinColumn(name="code", nullable=true)
private List <MapFields> mapFields;
}

public class MapFields
{
private int id;
private string code;
}

How can I do this sql query using hibernate criteria.

SELECT COUNT(*)
FROM 
(
    SELECT MapFields.code
    FROM Client LEFT JOIN MAPFields on Client.code
    GROUP BY MapFields.code
    HAVING COUNT(MapField.code) > 10
) AS A

I have tried the following but to no avail. I keep encountering an exception that tell me that a property can not be resolved.

org.hibernate.QueryException: could not resolve property: numberOfMapFields of: …Client

Criteria criteria = getCurrentSession().createCriteria(Client.class)

criteria.createAlias("mapFields", "mapFields", CriteriaSpecification.Left_Join)

ProjectionList pl = Projections.projectionList();

pl.add(Projections.count("mapFields.code", "numberOfMapFields"));

pl.add(Projections.rowCount());

criteria.setProjection(projectionList);

criteria.add(Restriction.ge("numberOfMapFields", "10"))

criteria.list();

PLEASE can anyone provide a code snippet on how to do this using hibernate criteria and if you need more information just tell me and i will try to provide more information.

  • 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-05-29T09:17:08+00:00Added an answer on May 29, 2026 at 9:17 am

    selects in the from clause are not supported by criteria. either use hql or sql – Firo

    Doh! Thanks for the information…

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

Sidebar

Related Questions

Can anyone help me create a regular expression that accepts alphanumeric (numbers and letters
Can anyone help me with this? I have a task to write a function,
Can anyone help me how to create a JSON Object from the database? This
Can anyone help me understand why this line doesn't create an image with a
Can anyone help me convert this from Oracle to SQL Server 2008? CREATE SEQUENCE
Can anyone help me make sense of the following? I create a few squared
Can anyone help me create a javascript/jquery function to control the HTML5 audio tag
I need to create HTML pop-up menu using Perl. Can anyone help me?
Can anyonen help with Teradata? I want to create a query that is a
Can anyone help with this... vector<unsigned int> *vVec = new vector<unsigned int>; vVec .reserve(frankReservedSpace);

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.