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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:19:38+00:00 2026-05-12T08:19:38+00:00

I have a question about nHibernate and filtering. I am using nHibernate 2.2 but

  • 0

I have a question about nHibernate and filtering. I am using nHibernate 2.2 but I think this will apply to versions as early as 1.2.

I have created a simple example to illustrate the problem. I have three domain objects: Country, State, and City (assume the DB tables match the domain and have the appropriate relations defined. I want to select cities that belong to a specific country using nHibernate filters. I believe I’ve set up the filters correctly and the filter by state (the parent) works great.

I have included the domain model and my nHibernate mapping below. My query is a simple HQL statement: select f from city f

Country
 CountryId int
 Name      string
 States    list

State
  StateId   int
  Name      string
  Country   object
  Cities    list
City
  CityId    int
  Name      string
  State     object

nHibernate Mapping:

    <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CMDB.Model" namespace="CMDB.Model">
  <class name="Country" table="Country" lazy="false">
    <id name="CountryId" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="Name" type="string"/>
    <bag name="States" table="State" inverse="true" lazy="false" cascade="all-delete-orphan">
      <key column="StateId"/>
      <many-to-many class="State" column="StateId"/>
      <filter name="ByCountry" condition=":CountryId = CountryId"/>
    </bag>
  </class>
  <class name="State" table="State" lazy="false">
    <id name="StateId" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="Name" type="string"/>
    <many-to-one name="Country" column="CountryId" class="Country" lazy ="false" />
    <bag name="Cities" table="City" inverse="true" lazy="false" cascade="all-delete-orphan">
      <key column="CityId"/>
      <many-to-many class="City" column="CityId"/>
      <filter name="ByState" condition=":StateId = StateId"/>
    </bag>
    <filter name="ByCountry" condition=":CountryId = CountryId"/>
  </class>
  <class name="City" table="City" lazy="false">
    <id name="CityId" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="Name" type="string"/>
    <many-to-one name="State" column="StateId" class="State" lazy ="false" />
    <filter name="ByState" condition=":StateId = StateId"/>
  </class>
  <filter-def name="ByCountry">
    <filter-param name="CountryId" type="int"/>
  </filter-def>
  <filter-def name="ByState">
    <filter-param name="StateId" type="int"/>
  </filter-def>
</hibernate-mapping>
  • 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-12T08:19:38+00:00Added an answer on May 12, 2026 at 8:19 am

    I spent a lot of time researching this and determined that nHibernate will not apply nested filters. The solution is to handle the problem programatically and start with the parent, returning a filterered list and then building a list of all the children belonging to the filtered parents.

    So, in my example I would load all states belonging to a particular country and then build a list of the states child cities.

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

Sidebar

Related Questions

I have figured out a lot about nhibernate, but this seems to be my
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
this is more of a subjective Question, but I'll ask it anyway. I'm about
I have this simple query: ICriteria crit = session.CreateCriteria(typeof(Article)); crit.CreateCriteria(Category, global::NHibernate.SqlCommand.JoinType.InnerJoin) .Add(Restrictions.Eq(Name, Fun)); This
Warning - I am very new to NHibernate. I know this question seems simple
I have a question about joins in NHIBERNATE. We had an issue with our
I'm studying Fluent NHibernate now, and have a question about mapping. It's not an
I have a question about how to do data filtering with RequestFactory in GWT.
I have a question about transaction on NHibernate. As far as i know there
I'm writing my first NHibernate application, but I guess this question applies to any

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.