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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:50:08+00:00 2026-06-01T04:50:08+00:00

I have a pretty complex criteria, which I use to retrieve, sort and page

  • 0

I have a pretty complex criteria, which I use to retrieve, sort and page server-side data. I stripped down the following excerpt:

    // create criteria over a bunch of tables...
    Criteria testCriteria = getSession().createCriteria(PriceRequest.class)
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .setFetchMode("pricedBy", FetchMode.JOIN)
            .setFetchMode("canceledBy", FetchMode.JOIN)
            .setFetchMode("product", FetchMode.JOIN)
            .setFetchMode("product.underlyings", FetchMode.JOIN)
            .setFetchMode("product.tradedBy", FetchMode.JOIN)
            .setFetchMode("product.requestedBy", FetchMode.JOIN)
            .setFetchMode("fileUploads", FetchMode.JOIN);

    // add various filter fields (only if required in real code)...
        Criteria subCriteria = testCriteria
                .createCriteria("product", JoinFragment.LEFT_OUTER_JOIN)
                .setFetchMode("underlyings", FetchMode.JOIN)
                .add(Restrictions.ge("maturityDate", new Date()));

        testCriteria.addOrder(Order.desc("product.id")); // (1)
        testCriteria.addOrder(Order.desc("product.maturityDate")); // (2)

        List list = testCriteria.list();

Statement (1) runs fine, statement (2) ends with the following exception:

SEVERE: Servlet.service() for servlet rest threw exception
org.hibernate.QueryException: could not resolve property:
product.maturityDate of: com.my.model.PriceRequest

I picked “maturityDate” as an example, but I’m having this issues with all product properties except “product.id”.

I also tried adding an alias for product (“prod”). This allows to sort by maturity date (“prod.maturityDate”), but fails on adding the restriction to subcriteria.

I so much have no clue what’s going wrong…

  • 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-01T04:50:09+00:00Added an answer on June 1, 2026 at 4:50 am

    createCriteria(association) does not create an alias but you need one for the orderby

    Also you cant filter on an association and eager fetch it because you might filter out entities of the association which are needed to initialize it hence the fetchmode is ignored. Use a correlated subquery

    // create criteria over a bunch of tables...
    Criteria testCriteria = getSession().createCriteria(PriceRequest.class)
            .setFetchMode("pricedBy", FetchMode.JOIN)
            .setFetchMode("canceledBy", FetchMode.JOIN)
            .createAlias("product", "prod")
            .setFetchMode("prod.underlyings", FetchMode.JOIN)
            .setFetchMode("prod.tradedBy", FetchMode.JOIN)
            .setFetchMode("prod.requestedBy", FetchMode.JOIN)
            .setFetchMode("fileUploads", FetchMode.JOIN)
            .addOrder(Order.desc("prod.maturityDate"));       // (2)
    
    // add various filter fields (only if required in real code)...
    if (...)
    {
        Criteria subCriteria = getSession().createCriteria(PriceRequest.class)
            .createCriteria("product", JoinFragment.LEFT_OUTER_JOIN)
            .add(Restrictions.ge("maturityDate", new Date()));
            .setResultTransformer(Projection.id)
    
        testCriteria = testCriteria
            .add(Subqueries.PropertyIn("id", subCriteria));
            .setFetchMode("underlyings", FetchMode.JOIN)
    }
    
    List list = testCriteria.list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty complex JSF page (we use JSF2 with facelet) in which
We have a pretty complex BizTalk interface which uses the HL7 accelerator. We use
I have a HTML page which a pretty complex layout ( see here ).
I am using Extjs 3.3.1 I have a pretty complex page, and I cannot
I have to create a pretty complex map which is divided in pieces, which
I have a pretty complex object graph G with an object o1 in G
I have a pretty complex database schema and would like to know if there
I have a pretty complex linq statement I need to access for different methods.
I have a pretty complex form with lots of inputs and validators. For the
I have a pretty complex chat application going on, and there are multiple chat

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.