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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:46:58+00:00 2026-06-11T08:46:58+00:00

class A{ // one to many mapping List<B> listOfB; //getter and setter; class B

  • 0
    class A{
// one to many mapping
    List<B> listOfB;
    //getter and setter;
    class B {
    String s;
    //getter and setter
    }

Now, when I get class A , it will return all the associated class Bs in listOfB. But I need certain condition on which of B should be in response. Like Get A such that listOfB contains all such B for which s = ‘something’.

EDIT : currently this is not working:

select a from A a where a.listOfB IN (select b from a.listOfB b where b.s='something');
  • 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-11T08:46:59+00:00Added an answer on June 11, 2026 at 8:46 am

    1) I assume that you mapped a one-to-many relation from A to B like A.listOfB = B.b

    I think your query can be simplified as:

    select a 
    from A a, B b
    where a.listOfB = b.b
    and where b.s='something'
    

    The equivalent Hibernate Criteria query would be:

    List results =  sess.createCriteria(A.class)  
        .createCriteria("listOfB")
        .add(Restrictions.eq("s", "something"))
        .list();
    

    2) If there is no relation mapped between these entities you can use an SQLRestriction over the field a.listOfB

    List results = sess.createCriteria(A.class)
    .add( Restrictions.sqlRestriction("{alias}.listOfB in (selec b from B where b.s = ?)), "something", Hibernate.STRING) )
       .list();
    

    More examples here.

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

Sidebar

Related Questions

In nhibernate, I have two classes that are associated with a many-to-one mapping: <class
I've got a class with many string arrays. I'd like to have one generic
I m using one-to-many mapping for List using join table. There are lot of
I can set up one-to-many mapping of List objects by using annotations, however using
I've two tables: CompanyRating and RatingMeasure CompanyRating will have one-to-many mapping with RatingMeasure Here
I have only one class with many instances. Every instance is observer of couple
For example. class One(models.Model): text=models.CharField(max_length=100) class Two(models.Model): test = models.Integer() many = models.ManyToManyField(One, blank=True)
How would I show one of many nested objects in the index view class
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have one abstract class and many child classes. In child classes are from

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.