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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:01:04+00:00 2026-05-20T20:01:04+00:00

I have common parent\children scenario: public class Order : AdvancedBaseOrder { ICollection<ProducerRelation> producers =

  • 0

I have common parent\children scenario:

public class Order : AdvancedBaseOrder
{

    ICollection<ProducerRelation> producers = new List<ProducerRelation>();
    public virtual ICollection<ProducerRelation> Producers
    {
        get { return producers; }
        set { producers = value; }
    }
}

public class ProducerRelation : BaseProducerRelation
{
    public virtual Order Order { get; set; }
    public virtual int Number { get; set; }
}

Mappings:

Order.hbm.xml
....
<set name="Producers" cascade="all-delete-orphan" inverse="true">
  <key column="order_id"/>
  <one-to-many class="ProducerRelation,Avtobus66.Core"/>
</set>
....


ProducerRelation.hbm.xml
....
 <many-to-one name="Order" class="Order, Avtobus66.Core" column="order_id" cascade="none"/>
<property name="Number" >
  <column name="number"/>
</property>
....

When I run this code:

            Order order = (Order)session.Get(typeof(Order), 23);
            var a = new ProducerRelation();
            a.Number = 6;
            a.Order = order;

            var b = new ProducerRelation();
            b.Number = 7;
            b.Order = order;

            order.Producers.Add(a);
            order.Producers.Add(b);
            session.Merge(order);
            session.Flush();

only one of my children is added. I know, that nhibernate is “watching” the child collection for changes, but what I do wrong? Why nhib can’t add two children?

SQL:

 NHibernate: SELECT ... WHERE this_.id = ?p0;?p0 = 23
 NHibernate: INSERT INTO gb_avtobus66.ekbprint_producer_relation (producer_price, producer_price_clean, order_id, ekbprint_product_id, client_id, number) VALUES (?p0, ?p1, ?p2, ?p3, ?p4, ?p5);?p0 = 0, ?p1 = 0, ?p2 = 23, ?p3 = NULL, ?p4 = NULL, ?p5 = 6
 NHibernate: SELECT LAST_INSERT_ID()
  • 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-20T20:01:04+00:00Added an answer on May 20, 2026 at 8:01 pm

    I suspect it is because of the fact that you’re using a set collection type. A set is an unordered collection that contains no duplicates. So likely it’s looking at the two new children and thinks that the second one is a duplicate. Make sure you override Equals/GetHashcode to indicate what is a duplicate entry.

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

Sidebar

Related Questions

I want to create templates for base new reports on to have common designs.
I have a common code of serializing a class object in my 3-4 methods
Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with
After storing objects of different types in the same container using common parent class
I have a parent master table that is generic enough to hold the common
We have several common libs. Ideally we want them all to use the latest
i have several common elements (components), that will generate some html. it seems my
We have a common problem of moving our development SQL 2005 database onto shared
I have a project where there are multiple applications that have some common configuration
I would love to be able to have a common set of Classes in

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.