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

  • Home
  • SEARCH
  • 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 3785876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:35:45+00:00 2026-05-19T11:35:45+00:00

I have the following mapping file for ‘Photo’ objects (edited for brevity): <hibernate-mapping …

  • 0

I have the following mapping file for ‘Photo’ objects (edited for brevity):

<hibernate-mapping ... default-access="property" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Photo" table="Photos">
    <id name="PhotoId" unsaved-value="0">
        <column  name="PhotoId" />
        <generator class="native" />
    </id>
    ...
    <bag name="Comments" table="Comments" lazy="false" order-by="DateTimePosted desc" cascade="all-delete-orphan" inverse="true">
        <key column="PhotoId" />
        <one-to-many class="Comment" />
    </bag>
</class>

I want to apply a Where clause against the ‘Comments’ bag to only retrieve Comments with the ‘Approved’ property = true. However, when I had this in place I came up against a problem scenario where deleted Photo objects were not then cascading deleted unapproved comments (and were leaving orphaned comment records) as it didn’t meet the condition of the where clause! In essence, I wanted the where clause to be adhered to EXCEPT for cascading deletes, in which case, I ALWAYS wanted any comments associated with a photo to be deleted, when a Photo was deleted.

Here is an edited copy of my Comments mapping file:

<hibernate-mapping ... default-access="property" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Comment" table="Comments">
    <id name="CommentId" unsaved-value="0">
        <column name="CommentId"></column>
        <generator class="native" />
    </id>
    <property name="DateTimePosted" not-null="true" />
    ...
    <property name="Approved" not-null="true" />
    <many-to-one name="Photo">
        <column name="PhotoId" />
    </many-to-one>
</class>

How can I get around this?

  • 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-19T11:35:45+00:00Added an answer on May 19, 2026 at 11:35 am

    Since NHibernate can’t guess that you “wanted the where clause to be adhered to EXCEPT for cascading deletes”, you need to use filters to get the collection items instead.

    An alternative is using a LINQ-to-objects projection:

    public virtual IEnumerable<Comment> ApprovedComments
    {
        get { return Comments.Where(c => c.Approved); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mapping file: <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=Project1.Accounts namespace=Project1.Core.Domain>
I have the following mapping for the birth date in the hbm.xml file <property
I have the following mapping: <hibernate-mapping package=server.modules.stats.data> <class name=User table=user> <id name=id> <generator class=native></generator>
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
I have the following mapping in my Castle Windsor xml file which has worked
I have created the following mapping in my vimrc file: noremap <C-p> ! firefox
Consider the following Hibernate mapping file: <hibernate-mapping ...> <class name=ContentPackage table=contentPackages> <id name=Id column=id
I have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>
I have the following mapping for my table in MySql: <class name=Tag, namespace table=tags
I have the following mapping: public class LogEntryMap { public LogEntryMap() { Map.Id(x =>

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.