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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:17:38+00:00 2026-05-28T03:17:38+00:00

I have 2 classes with HasMany relationship, say a class called Parent that has

  • 0

I have 2 classes with HasMany relationship, say a class called Parent that has a collection of Children. I want to be able to build queries in NHibernate that would only return Parents that have Children. I guess that to do that I need to have this HasMany relationship.

What I want though is following – when I load Parents, I don’t want it’s children to be loaded. Kind of LazyLoading, but without loading Children at all.

Any ideas how to accomplish 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-28T03:17:38+00:00Added an answer on May 28, 2026 at 3:17 am

    NHibernate’s LazyLoading of collections is exactly what you asked for. The collection-object itself is created but none of the child objects is loaded.

    When JSON method is called Children objects are loaded lazily. I want to avoid it.

    3 Options come to mind

    1. projecting the Parentobject into a DTO which is then serialized
    2. Customizing the JSON serialization
    3. detaching the parent from the session (Evict()) and setting the collection to null before serializing

    i would favor option 1, but option 2 would be ok too. Option 3 would be a hack and should be avoided

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

Sidebar

Related Questions

Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{
Say I have a table animals that has a column parent_id Say also that
I have a working model, but have noticed that the relationship has been created
I have a Parent class with two lists of Child classes public class Parent
I have two classes in Grails application , Employee has hasMany(one To Many relations)
i have the following (simplified) domain classes class Filter { String name static hasMany
Suppose you have the following domain classes class User { static hasMany = [books:Book]
Hello I have the follwing domain classes. class Student { int age static hasMany
i have domain classes: package test class Credit { String name; static hasMany =
I am using Nhibernate for my ORM. I have a class Control that has

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.