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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:58:30+00:00 2026-06-09T07:58:30+00:00

Here I am facing an issue in hibernate criteria usage, I have created criteria

  • 0

Here I am facing an issue in hibernate criteria usage, I have created criteria for multiple tables and added restrictions but the output is not as expected

My code:

final Criteria crit = session2.createCriteria(Item.class, "item");   
            crit.createCriteria("itemvalues", "values");   
            crit.createCriteria("categoryitemses", "catItems");   
            crit.createCriteria("catItems.category", "cat");   
            crit.createCriteria("cat.categorytype", "catType");    
            crit.createCriteria("cat.categoryproducts", "catProd");    
            crit.createCriteria("catProd.product", "prod");    
            crit.createCriteria("prod.customer", "cust");   
            crit.add(Restrictions.eq("catType.id", id));   
            crit.add(Restrictions.eq("cust.id", custId));   
            crit.add(Restrictions.eq("values.inputkey", "previewimage"));   
            crit.addOrder(Order.asc("item.id"));

In Item.java I have the following properties

private Itemtype itemtype;   
private String name;   
private String description;   
private Set<Itemvalue> itemvalues = new HashSet<Itemvalue>(0);   
private Set<Categoryitems> categoryitemses = new HashSet<Categoryitems>(0); 

ItemValue table contain a field name inputkey which contains entries like previewimage and content but all I need is only to retrieve previewimage inputkeys.

But in the output inputkeys comes with some other values also.

I have found that the query generated by hibernate is running correctly and gives output as expected but after that queries there are several other queries also executed when I retrieve the itemvalue using the set

final Set<Itemvalue> itemValues = itemList.get(innerIndex).getItemvalues();   
final Iterator<Itemvalue> itemVals = itemValues.iterator();    
while(itemVals.hasNext()) {   
jobj.put("Location", itemVals.next().getValue());    
}

Here in the line itemValues.iterator hibernate query executed 17 times since the overall output is 17 items and each item it fetches the itemvalue but omits the condition given earlier

crit.add(Restrictions.eq("values.inputkey", "previewimage")); 

What I am missing here? Anyone please help me to resolve this!

Thanks in advance,
Karthi.

  • 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-09T07:58:31+00:00Added an answer on June 9, 2026 at 7:58 am

    Your original query uses the Restrictions.eq("values.inputkey", "previewimage") restriction to filter out Item objects and not Itemvalue objects.

    When getItemvalues() is called the Hibernate collection mapping is used to retrieve the objects and not the original query. If there is nothing special about the collection mapping, the unfiltered collection of related item values objects will be returned.

    You could try to configure a filter on the collection mapping or just execute a new criteria for each item to retrieve the filtered desired itemvalue collection.

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

Sidebar

Related Questions

I am new to makefiles and facing some issue with it. I have created
I am posting multiple images to server url,But i am facing one issue. After
I am facing a issue here in reading the values set by a stored
I'm facing an issue here. For Facebook debugging reasons, I made a host entry
Here I am facing a problem with the displaying of multiple pins at time
Here i am facing a problem that , i configured the hibernate sessionfactory in
So here is the problem that I am facing: I have an application that
I am facing some issue in my listener while implementing JobQueueEvent, here is my
I'm facing a issue with opening mail client using openURL. Here is the code.
ghost noscript tag more info here I am facing exactly this issue, how shall

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.