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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:07:52+00:00 2026-05-15T03:07:52+00:00

I am getting the following exception. NHibernate.PropertyValueException : not-null property references a null or

  • 0

I am getting the following exception.

NHibernate.PropertyValueException : not-null property references a null or transient

Here are my mapping files.

Product

  <class name="Product" table="Products">
    <id name="Id" type="Int32" column="Id" unsaved-value="0">
      <generator class="identity"/>
    </id> 
    <set name="PriceBreaks" table="PriceBreaks" generic="true" cascade="all" inverse="true" >
      <key column="ProductId" />
      <one-to-many class="EStore.Domain.Model.PriceBreak, EStore.Domain" />
    </set>    

  </class>

Price Breaks

 <class name="PriceBreak" table="PriceBreaks">
    <id name="Id" type="Int32" column="Id" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name="ProductId" column="ProductId" type="Int32" not-null="true" />

    <many-to-one name="Product" column="ProductId" not-null="true" cascade="all" class="EStore.Domain.Model.Product, EStore.Domain" />  

  </class>

I get the exception on the following method

[Test]
public void Can_Add_Price_Break()
{

    IPriceBreakRepository repo = new PriceBreakRepository();

    var priceBreak = new PriceBreak();

    priceBreak.ProductId = 19;
    repo.Add(priceBreak);

    Assert.Greater(priceBreak.Id, 0);
}

Following up on Jan reply. I’ve removed the ProductId from priceBreak map. This works!!

    public int AddPriceBreak(Product product, PriceBreak priceBreak)
    {


        using (ISession session = EStore.Domain.Helpers.NHibernateHelper.OpenSession())
        using (ITransaction transaction = session.BeginTransaction())
        {

            product.AddPriceBreak(priceBreak);
            session.SaveOrUpdate(product);
            transaction.Commit();
        }

        return priceBreak.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-15T03:07:53+00:00Added an answer on May 15, 2026 at 3:07 am

    Remove the ProductId property from the mapping and from the PriceBreak class. And use the PriceBreaks collection to add PriceBreaks, you don’t need the PriceBreakRepository, but only a ProductRepository.

    Example:

    using (var session = sessionFactory.OpenSession()) 
    {
      using (var tx = session.BeginTransaction()) 
      {
    
        var product = session.Get<Product>(19);
        product.AddPriceBreak(new PriceBreak());
    
        tx.Commit();
       }
     }
    

    And in the Product:

    class Product 
    {
       // ...
       public void AddPriceBreak(PriceBreak pb) 
       {
         pb.Product = this;
         PriceBreaks.Add(pb);
       }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following exception: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: Entity class header:
I have created mock: GuiExHandler mockGuiEx = EasyMock.createMock(MockedClass.class); And Im getting following exception: Testcase:
I am getting the following exception while adding data into database: org.hibernate.HibernateException: The database
I am getting Following Exception while configuring the Connection Pool in Tomcat This is
I'm getting the following exception when I run my application in Release mode from
I am getting the following exception when i try to use the fetchall method
I am getting the following exception: Nullable object must have a value Everything was
I'm getting the following exception when executing the first preparedstatement after a period of
I am getting he following Exception while running my Quartz Schdular program. Below is
hi i am getting the following exception while running my application and my applicationContext.xml

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.