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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:31:42+00:00 2026-05-18T08:31:42+00:00

I have come across a weird problem concerning composite keys and one-to-many relationship. I

  • 0

I have come across a weird problem concerning composite keys and one-to-many relationship.

I have the following Invoice class:

public class Invoice: AccountingBase<InvoiceItem>
{
    public virtual IList<InvoiceItem> InvoiceItems {.....}
}

the class it inherits is (AccountingBase) is as follows:

public abstract class AccountingBase<TItemType>  : AccountingBase where TItemType : AccountingItemBase
{
    public virtual ObservableCollection<TItemType> Items { get; set; }

    public abstract void AddItem(TItemType item);
}

And the bottom class is:

public abstract class AccountingBase
{
    public virtual Subsidiary Subsidiary {....}
    public virtual int ID{ ....}
}

The Mapping for Invoice class is as follows:

 <class name="Invoice" table="Invoice">
     <composite-id>
       <key-many-to-one class="Subsidiary" name="Subsidiary"/>
       <key-property name="ID" column="InvoiceID" />
     </composite-id>
     <bag name="InvoiceItems" table="InvoiceItem" inverse="true" lazy="false">
       <key>
         <column name="Subsidiary" />
         <column name="InvoiceID" />
       </key>
       <one-to-many class="InvoiceItem" />
     </bag>   
 </class>

Now when i retrieve a list of Invoices it works fine, including lazily loading each Items object. The problem i get is, when i select an invoice to edit. I open a new session, and i try retrieve the same invoice using the new session, but when it loads the invoice, it doesnt load the items, it retrieves them as blank, although when i run the generated SQL manually it runs perfectly fine. What could be the reason?

The code i am running to retrieve to get the new Invoice object in the new session using the old object is:

Invoice = Session.Get<Invoice>(invoice);

When i debug, invoice is of Type Invoice, and also, invoice has 1 InvoiceItem in InvoiceItems collection, but the new instance in Invoice, all the fields are populated but the InvoiceItems is null. Is there anything i should know about Nhibernate that might cause this kind of error?

I have tried lazy="false".

  • 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-18T08:31:42+00:00Added an answer on May 18, 2026 at 8:31 am

    Found the fix, i had to correctly implement Equality methods, in both Invoice class and Subsidiary class.

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

Sidebar

Related Questions

I have come across a weird problem when working with files in python. Let's
I've come across a weird problem whilst trying to optimise the following image: It
I have come across a bit of a problem. I have a class called
I have come across the following type of code many a times, and I
I have come across the following problem. I have a horizontal menu bar I
I have come across a very weird error. I'm on Solaris 10, using Ruby
I have come across a situation (which I think is weird but is possibly
I have come across an annoying problem. I have made a system and now
I have come across the following basic Tree conflict: Local add, incoming add upon
I have come across many articles which warn against using links to provide logout

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.