Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate doesnt save object and also no error is showed
    primarykey
    data
    text
    <p>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.</p> <p>I use composite key in table "order_product". Table is child of "order".</p> <p>Database table: <strong>order_product</strong></p> <pre><code>order_id (PK) product_id (PK) count price </code></pre> <p>Mapping:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"&gt; &lt;class name="Service.OrderProduct, Service" lazy="true" table="order_product"&gt; &lt;composite-id&gt; &lt;key-property name="productId" column="product_id" type="string"/&gt; &lt;key-property name="orderId" column="order_id" /&gt; &lt;/composite-id&gt; &lt;property name="count" type="int" column="count" not-null="true" /&gt; &lt;property name="price" type="double" not-null="true" /&gt; &lt;many-to-one name="Order" column="order_id" fetch="join" cascade="all"/&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>C# Object:</p> <pre><code>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) &amp;&amp; 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; } } </code></pre> <p>Save code:</p> <pre><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); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload