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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:54:40+00:00 2026-05-16T15:54:40+00:00

I have problem with saving object to database with NHibernate. Program throws no error

  • 0

I have problem with saving object to database with NHibernate. Program throws no error but record is still not in database. I am also outputting sql queries and the query is not executed.

I use composite key in table “order_product”. Table is child of “order”.

Database table: order_product

order_id (PK)
product_id (PK)
count
price

Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
  <class name="Service.OrderProduct, Service" lazy="true" table="order_product">
    <composite-id>
      <key-property name="productId" column="product_id" type="string"/>
      <key-property name="orderId" column="order_id" />
    </composite-id>
    <property name="count" type="int" column="count" not-null="true" />
    <property name="price" type="double" not-null="true" />
    <many-to-one name="Order"   column="order_id"   fetch="join" cascade="all"/>
  </class>
</hibernate-mapping>

C# Object:

public class OrderProduct
{
    virtual public OrderProductPK orderProductPK { get; set; }
    virtual public int count { get; set; }
    virtual public string productId { get; set; }
    virtual public int orderId { get; set; }
    virtual public double price { get; set; }
    virtual public Order Order { get; set; }

    public override bool Equals(Object o)
    {

        OrderProduct a = o as OrderProduct;
        if (a.productId.Equals(this.productId) && a.orderId==this.orderId)
        {
            return true;
        }
        return false;
    }
    public override int GetHashCode()
    {
        int hashCode = 0;
        hashCode = hashCode ^ productId.GetHashCode() ^ orderId.GetHashCode();
        return hashCode;
    }
}
public class OrderProductPK
{
    virtual public string productId { get; set; }
    virtual public int orderId { get; set; }

}

Save code:

OrderProduct op = new OrderProduct();
op.order_id= 133;
op.product_id = "product_key_id";
op.price = 20.4;
op.count = 10;
OpenSession().Save(op);
  • 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-16T15:54:41+00:00Added an answer on May 16, 2026 at 3:54 pm

    I solved my problem using surrogate key.

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

Sidebar

Related Questions

Hi I have a problem saving 2 tables of my database at the same
I am using CakePHP framework with MySQL database and I have problem in saving
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem for bulk insert of the file.I am saving the multiple record
I have a PHP class that stores database query results, but also contains a
I have a problem with saving the path in doctrine from a file upload.
I'm using DDD and NHibernate to persist my domain object. In my database every
heres the problem, i have a database thats hold information on marker images: i'm
I'm making a program with c# and sql server and I have a problem
I am writing an application and I finally have it saving to the database

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.