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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:03:56+00:00 2026-05-15T15:03:56+00:00

I have an class which has a collection, mapped as a bag in my

  • 0

I have an class which has a collection, mapped as a bag in my nHibernate mapping file for that class, and I wish to return all instances of that class whose collection has a one or more of the objects which I pass in.

Example:

My Parent Class is called DocumentDefinition. It has a collection of Roles, which is a nHibernate entity, that the document can be accessed by. These two are connected via a Many-To-Many mapping. I want to pass the query a collection of roles and return all DocumentDefinition instances which have one or more of one of those roles passed in.

Mapping on Parent class, DocumentDefinition:

 <bag name="AllowedRoles" table="Many-To-Many Table" lazy="false">
      <key column="ParentDefinition" /> //Column from Many-To-Many Table
      <many-to-many class="MyRolesClass" column="ParentRole" /> //Column from Many-To-Many Table
 </bag>

Example of what I have tried so far:

Select distinct d from DocumentDefinition d, MyRolesClass r where r in :roles and r in elements(d.Group)

Roles being the collection I wish to pass in.

So how do I do a query to return DocumentDefinitions where r (Roles Class) is in both the parameter list passed in and the collection on the DocumentDefinition object.

Hope that’s clear! Cheers!

  • 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-15T15:03:56+00:00Added an answer on May 15, 2026 at 3:03 pm

    You were very close… the query should be:

    select distinct d
    from DocumentDefinition d, MyRolesClass r
    where r in (:roles) and r in elements(d.AllowedRoles)
    

    And you send the desired roles using .SetParameterList("roles", collectionOfRoles).

    BTW, I changed the collection name which didn’t match the mapping you posted.

    One more thing to consider: lazy=”false” is almost always a bad idea for collections.

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

Sidebar

Related Questions

I have a class called SynonymMapping which has a collection of values mapped as
I have a Person class which has a String collection of aliases representing additional
I have a class say: ClassA which has a collection of ClassB @OneToMany(cascade =
I have a method which should consider a collection of instances of a class
I have a class 'Collection', which has an add method. The add method should
I have a class testviewModel which has implemented INotifychanged event and all its proeprties.
I have a Collection class which has many coins. I am trying to select
I have an entity which has a collection as one of its attributes. That
I have an ItemEntity class, which has a collection of ImageEntity's. I want to
I have a class which has a collection public class Parent { ... ISet<Child>

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.