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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:16:16+00:00 2026-06-09T23:16:16+00:00

Consider objects like these: public partial class Record { public int RecordID {get; set;}

  • 0

Consider objects like these:

public partial class Record
{
    public int RecordID {get; set;}
    public DateTime? Created { get; set; }
    public int CreatorUserUserObjectNDX { get; set; }
    public UserObject Creator { get; set; }
    ...
}

and

public partial class UserObject
{
  public virtual int ID {get; set;}
  public virtual string Name {get; set;}
}

and their mappings like:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="..." namespace="..." assembly="...">
<class name="Record" table="records" lazy="false" schema="..">
    <id name="RecordID" column="ndx">
        <generator class="native" />
    </id>
    <property name="Created" column="created" />
    <property name="CreatorUserUserObjectNDX" column="creator_user_user_object_ndx" />

    <many-to-one name="Creator" column="creator_user_user_object_ndx" lazy="proxy"/>
</class>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="..." namespace="..." assembly="...">
<class name="UserObject" table="user_objects" lazy="false">
    <id name="NDX" column="ndx">
        <generator class="native" />
    </id>

    <property name="Name" column="name" />
</class>

They are kept simple intentionally here, in real they’re more heavy with one-to-many collections etc, but these work, so they’re not the point here.

The problem I ran into is, when I use definitions & mappings like these, and do a simple

var results = session.QueryOver<Record>()
  .List();

NHibernate does NOT create a proxy for the creator property, it just uses left outer joins in the executed SQL statement and inserts a UserObject directly.
When I change lazy='false' to lazy='true' within the mapping for UserObject it works, proxy is created and the executed SQL has no outer joins.

So, is it strictly necessary to set lazy='true' for all classes, that may be a reference anywhere? I thought I could use set it to false per default for all mappings and set lazy='proxy' in the many-to-one definition, when needed.

I use NHibernate 3.2, so no config about proxyfactory. What am I missing here?

  • 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-09T23:16:17+00:00Added an answer on June 9, 2026 at 11:16 pm

    If you set lazy=false in your mapping, there is no need for NHibernate to create a proxy, because all properties will be eagerly loaded.

    You should not change lazy loading settings unless it is required that you do eager loading. Even then, you can use “fetch” (in hql for example) to eagerly load what you need.

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

Sidebar

Related Questions

Consider the following simplified objects and relationships: public class Job{ int JobId; String name;
Consider this code: class First { public: int y; First() { y = 90;
Consider this code sample: public abstract class Parent { public int val; public Parent()
Consider these two classes: public class A { B b; public A(B b) {
Consider these properties, double _temperature; public double Temperature { get { return _temperature; }
Consider following class class test { public: test(int x){ cout<< test \n; } };
consider the following simplified example: public class Ticket { public int Id; public TicketState
Let's consider a chain of objects like this: Earth->Continent->Country->City->name Let's also consider Earth.class has
Consider the class: public class foo { public object newObject { get { return
Consider the following snippet: public class ReflectionTest { public static void main(String[] args) {

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.