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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:08:34+00:00 2026-06-07T06:08:34+00:00

I am getting filtered ‘Trainer’ entities, but collection (trainedMonkeys) is not filtered. ‘trainedMonkeys’ variable

  • 0

I am getting filtered ‘Trainer’ entities, but collection (trainedMonkeys) is not filtered. ‘trainedMonkeys’ variable is holding all ‘Monkey’ objects instead of holding only the one with ‘isThumb = true’.

Can someone please check if below criteria I am using is correct?

@SuppressWarnings("unchecked")
    public List<Trainer> listTrainers() {         
        Criteria crit = sessionFactory.getCurrentSession().createCriteria(Trainer.class)
        .createAlias("trainedMonkeys", "tm")
        .add(Restrictions.eq("tm.isThumb", true))
        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

Trainer.java

public class Trainer {  
    private Long trainerId;

    private String trainerName;

    public List<Monkey> trainedMonkeys;

Monkey.java

public class Monkey {

    private Long id;

    private String monkeyName;  

    private boolean isThumb;

I am executing below code in the controller,

for (Trainer trainer : trainerList){  
            System.err.println("<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>");  
            System.err.println("Trainer ID*****"+trainer.getTrainerId());  
            System.err.println("Trainer Name******"+trainer.getTrainerName());  
            monkeyList = trainer.getTrainedMonkeys();  
            for (Monkey monkey : monkeyList){  
                System.err.println("Monkey ID*****"+monkey.getId());  
                System.err.println("Monkey Name*****"+monkey.getMonkeyName());  
            }  
            System.err.println("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>");  
        }

and the output is as below (Monkey_2 and Monkey_6 are the only objects that should be present as only they satisfy the criteria) please help,

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>> 
Trainer ID*****88 
Trainer Name******TrainerSachin 
Monkey ID*****87 
Monkey Name*****Monkey_1 
Monkey ID*****88 
Monkey Name*****Monkey_2 
Monkey ID*****89 
Monkey Name*****Monkey_3 
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> 
<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>> 
Trainer ID*****89 
Trainer Name******TrainerVinod 
Monkey ID*****90 
Monkey Name*****Monkey_5 
Monkey ID*****91 
Monkey Name*****Monkey_6 
Monkey ID*****92 
Monkey Name*****Monkey_7 
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> 
  • 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-07T06:08:35+00:00Added an answer on June 7, 2026 at 6:08 am

    It should hold all. You misinterpret Criteria restrictions. Restrictionss filter which criterias returned entities should meet. They do not filter elements out from the collections in returned entities.

    Query returning entity with subset of relations to related entities would make things complex. Think about what should happen when such an entity is merged back to database.

    More details about subject can be found from Hibernate documentation.

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

Sidebar

Related Questions

I have this query but for some reason the StartDate values are not getting
I am trying to filter derived classes in my entities but i am getting
I'm getting used to the new IDE (it's vc# express), but the first contact
I have two variables : count, which is a number of my filtered objects,
How to get filtered products collection ids in extention. For current category we just
I'm not sure why, but I can't get this to work. var friends =
I am intermittently getting an System.InvalidCastException: Specified cast is not valid. error in my
Using the distance logic from this SO post , I'm getting back a properly-filtered
Problem: find ids that are in one file but not in another. Each file
I am new to not only python, but programming altogether so I'd appreciate your

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.