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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:43:46+00:00 2026-06-19T02:43:46+00:00

I’m somewhat new to NHibernate and I’ve run into a problem trying to join

  • 0

I’m somewhat new to NHibernate and I’ve run into a problem trying to join two tables. I have a name table and address table. I want to pull the name record regardless if any results are returned for the address record. If I have an address record in the code below works, but once the address record is removed I no longer receive the name record. I was trying this (NHibernate Left Outer Join), but it doesn’t work for me. Any ideas?

Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping 
    xmlns="urn:nhibernate-mapping-2.2" 
    namespace="Portlet.IncomingStudentInfo.Data.BusinessObjects" 
    assembly="Portlet.IncomingStudentInfo">
    <class name="ISINameMasterRecord" table="NAME_MASTER">
         <id name="NM_ID_NUM" column="ID_NUM" type="Int32">
            <generator class="native" />
        </id>
        <property name="NM_ID_NUM" column="ID_NUM" />
        <property name="NM_EMAIL_ADDRESS" column="EMAIL_ADDRESS" />
        <property name="NM_MOBILE_PHONE" column="MOBILE_PHONE" />
        <many-to-one name="LHP" class="ISILHPAddress" 
            column="ID_NUM" fetch="join" 
            foreign-key="ID_NUM" 
            outer-join="true" not-found="ignore" />
    </class>

    <class name="ISILHPAddress" table="ADDRESS_MASTER">
        <composite-id>
            <key-property name="AD_ID_NUM" column="ID_NUM" type="Int32" />
        </composite-id>
        <property name="AD_ID_NUM" column="ID_NUM" />
        <property name="AD_ADDR_CDE" column="ADDR_CDE" />
        <property name="AD_ADDRESS" column="ADDR_LINE_1" />
        <property name="AD_CITY" column="CITY" />
        <property name="AD_STATE" column="STATE" />
        <property name="AD_ZIP" column="ZIP" />
        <property name="AD_PHONE" column="PHONE" />
    </class>   
</hibernate-mapping>

Facade:

public class ISINameMasterRecordFacade : JICSBaseFacade<ISINameMasterRecord>
{
    public ISINameMasterRecord FindIDCriteria(int id)
    {
        ICriteria criteria = this.CreateCriteria();
        criteria.Add(Expression.Eq("NM_ID_NUM", id));

        criteria.CreateAlias(
            "LHP", 
            "lhp", 
            NHibernate.SqlCommand.JoinType.LeftOuterJoin);
        criteria.Add(
            Expression.Or(
                Expression.IsNull("lhp.AD_ADDR_CDE"), 
                Expression.Eq("lhp.AD_ADDR_CDE", "*LHP")));


        return criteria.UniqueResult<ISINameMasterRecord>();
    }
}
  • 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-19T02:43:47+00:00Added an answer on June 19, 2026 at 2:43 am

    Thanks for everyone’s help on this. I was speaking with another developer and he provided the following answer, which does work. Here’s some additional information on the issue. The NAME_MASTER table holds the name information for the record with the primary key being ID_NUM. The ADDRESS_MASTER table holds all the addresses for a record with the primary keys being ID_NUM and ADDR_CDE (they type of address it is: legal home permanent, email, summer address, etc.) A record may not have a *LHP (legal home permanent address), but may have other address records. We wanted to pull the NAME_MASTER record regardless of the presence of the *LHP address record, so this is really another condition on the join. Below is working and will pull the NAME_MASTER record regardless of the presence of a *LHP record in ADDRESS_MASTER.

    mappings.hbm.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Portlet.IncomingStudentInfo.Data.BusinessObjects" assembly="Portlet.IncomingStudentInfo">
      <class name="ISINameMasterRecord" table="NAME_MASTER">
        <id name="NM_ID_NUM" column="ID_NUM" type="Int32">
          <generator class="native" />
        </id>
        <property name="NM_ID_NUM" column="ID_NUM" />
        <property name="NM_EMAIL_ADDRESS" column="EMAIL_ADDRESS" />
        <property name="NM_MOBILE_PHONE" column="MOBILE_PHONE" />
    
        <bag name="Addresses" cascade="all" where="ADDR_CDE='*LHP'" lazy="false" fetch="join">
          <key column="ID_NUM"/>
          <one-to-many class="ISILHPAddress"/>
        </bag>
      </class>
    
    
      <class name="ISILHPAddress" table="ADDRESS_MASTER" lazy="false">
        <id name="AD_ID_NUM" column="ID_NUM" type="Int32">
          <generator class="native" />
        </id>
        <property name="AD_ID_NUM" column="ID_NUM" />
        <property name="AD_ADDR_CDE" column="ADDR_CDE" />
    
        <property name="AD_ADDRESS" column="ADDR_LINE_1" />
        <property name="AD_CITY" column="CITY" />
        <property name="AD_STATE" column="STATE" />
        <property name="AD_ZIP" column="ZIP" />
        <property name="AD_PHONE" column="PHONE" />
      </class>
    
    </hibernate-mapping>
    

    ISINameMasterRecordFacade.cs

    public ISINameMasterRecord FindIDCriteria(int id)
            {
                ICriteria criteria = this.CreateCriteria();
                criteria.Add(Expression.Eq("NM_ID_NUM", id));
    
                return criteria.UniqueResult<ISINameMasterRecord>();
            }
    

    ISINameMasterRecord.cs

    public class ISINameMasterRecord : EXBase
        {
            public virtual int NM_ID_NUM { get; set; }
            public virtual String NM_EMAIL_ADDRESS { get; set; }
            public virtual String NM_MOBILE_PHONE { get; set; }
    
            public virtual ISILHPAddress LHP
            {
                get { return Addresses != null && Addresses.Any() ? Addresses[0] : null; }
                set
                {
                    if (Addresses == null)
                        Addresses = new List<ISILHPAddress>();
    
                    if (Addresses.Any())
                        Addresses[0] = value;
                    else
                        Addresses.Add(value);
                }
            }
    
            //for mapping purposes
            protected virtual IList<ISILHPAddress> Addresses { get; set; }
    
    
            public ISINameMasterRecord()
            {
    
            }
        }
    

    ISILHPAddress.cs

    public class ISILHPAddress : EXBase
        {
            public virtual int AD_ID_NUM { get; set; }
            public virtual String AD_ADDR_CDE { get; set; }
            public virtual String AD_ADDRESS { get; set; }
            public virtual String AD_CITY { get; set; }
            public virtual String AD_STATE { get; set; }
            public virtual String AD_ZIP { get; set; }
            public virtual String AD_PHONE { get; set; }
    
            public ISILHPAddress() { }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from

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.