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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:58:21+00:00 2026-05-17T06:58:21+00:00

I have very simple situation and really don’t have a clue why this isn’t

  • 0

I have very simple situation and really don’t have a clue why this isn’t working.

This is my schema:

**[item]**
id (PK)
symbol

**[item_version]**
id (PK)
item_id (FK->ITEM)
symbol

These are my mappings:

item.hbm.xml

<class name="Core.Model.Entities.Item, Core.Model" table="item" lazy="false">
    <id name="Id" column="id" type="long">
        <generator class="native" />
    </id>
    <property name="Symbol" column="symbol"/>

    <bag name="ItemVersions" lazy="false" table="item_version" inverse="true" cascade="save-update">
        <key column="item_id" />
        <one-to-many class="Core.Model.Entities.ItemVersion, Core.Model"/>
    </bag>
</class>

*item_version.hbm.xml*

<class name="Core.Model.Entities.ItemVersion, Core.Model" table="item_version" lazy="false">
    <id name="Id" column="id" type="long">
        <generator class="native" />
    </id>

    <many-to-one name="Item" class="Core.Model.Entities.Item, Core.Model" column="item_id" cascade="save-update"/>
    <property name="Symbol" column="symbol"/>
    </class>

These are the classes:

Item.cs

public class Item : Entity<IItemDao>
{
   private long id;
   virtual public long Id
   {
       get { return this.id; }
       set { this.id = value; }
   }
   private string symbol;
   virtual public string Symbol
   {
       get { return this.symbol; }
       set { this.symbol = value; }
   }
   private IList<ItemVersion> item_versions = new List<ItemVersion>();
   virtual public IList<ItemVersion> ItemVersions
   {
       get { return this.item_versions; }
       set { this.item_versions = value; }
   }
}

ItemVersion.cs

public class ItemVersion : Entity<IItemVersionDao>
{
    private long id;
    virtual public long Id
    {
         get { return this.id; }
         set { this.id = value; }
    }
    private Item item = null;
    virtual public Item Item
    {
         get { return this.item; }
         set { this.item = value; }
    }
    private long item_id = 0;
    virtual public long ItemId
    {
         get { return this.item_id; }
         set { this.item_id = value; }
    }
    private string symbol;
    virtual public string Symbol
    {
         get { return this.symbol; }
         set { this.symbol = value; }
    }
}

And this code…

Item item = new Item();
item.Name = "test";

ItemVersion v = new ItemVersion();
v.Symbol = "test version";
item.ItemVersions.Add(v);

Item.Dao.Save(tmp);

… does not work. It inserts an item and throws an exception while inserting item_version row, that item_version.item_id cannot be null. So item_id property isn’t automatically set by NHibernate in ItemVersion object. Why cascade=”save-update” and inverse=”true” does not work in this case?

When I set manually, by adding this code:

v.Item = item;

and than call save, everything works fine, but this is not what I except from NHibernate – calling

item.ItemVersions.Add(v);

should be sufficient.

Am I doing something wrong or this is simply imposible? Thanks in advance for the answers 🙂

  • 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-17T06:58:22+00:00Added an answer on May 17, 2026 at 6:58 am

    You have to set v.Item because ItemVersions is inverse. That means the “other side” (the many-to-one) is in charge of maintaining the relationship.

    This is standard practice; to make it easier to use just add a method to Item:

    public void AddItemVersion(ItemVersion itemVersion)
    {
        ItemVersions.Add(itemVersion);
        itemVersion.Item = this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Afternoon. Im struggling with this situation. I have a very simple tabbed content inside
I have a quite strange situation. I have this very simple package: Task get
The situation is very simple, I have two panel. In the event of OnMouseOver
I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:
Very simple situation... very strange problem. I have a retained iVar NSMutableArray that I
The Situation I have a very compressed time schedule to write a simple (basically
i have some simple situation, but for me, it looks like very tough at
Supose we have a very simple model: Station has at least one Train Train
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As

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.