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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:16:44+00:00 2026-05-15T00:16:44+00:00

I have the fallowing problem: I have to tables SalesHeader and SalesPosition – where

  • 0

I have the fallowing problem:
I have to tables SalesHeader and SalesPosition – where SalesPosition is a child of SalesHeader.
Now. In table SalesHeader, there is a persistent Entity X. I try now to persist an Entity in SalesPosition with only give this Entity the Key to X (of SalesHeader). NHibernate does not have to save some data in SalesHeader. Now, when I flush the entity to SalesPosition, I become the fallowing exception:

object references an unsaved transient instance – save the transient instance before flushing.

at NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session)
at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session)
at NHibernate.Type.ManyToOneType.IsDirty(Object old, Object current, Boolean[] checkable, ISessionImplementor session)
at NHibernate.Type.TypeFactory.FindDirty(StandardProperty[] properties, Object[] x, Object[] y, Boolean[][] includeColumns, Boolean anyUninitializedProperties, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.FindDirty(Object[] currentState, Object[] previousState, Object entity, ISessionImplementor session)
at NHibernate.Event.Default.DefaultFlushEntityEventListener.DirtyCheck(FlushEntityEvent event)
at NHibernate.Event.Default.DefaultFlushEntityEventListener.IsUpdateNecessary(FlushEntityEvent event, Boolean mightBeDirty)
at NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event)
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event)
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()

this is my mapping of SalesPosition:

<class name="SalesPosition" table="SalesPosition" lazy="false"  >
    <id name="Id" column="Id" type="Guid">      
                    <generator class="assigned"/>
    </id>
  <version name="ObjectVersion" column="ObjectVersion"/>
  .... some fields
    <many-to-one  name="SalesHeader" class="SalesHeader" foreign-key="FK_SalesHeader_SalesPosition" >
        <column name="SalesHeaderId"/>
    </many-to-one>
</class>

and this is the mapping of SalesHeader:

<class name="SalesHeader" table="SalesHeader" lazy="false"  >
    <id name="Id" column="Id" type="Guid">      
                    <generator class="assigned"/>
    </id>
  <version name="ObjectVersion" column="ObjectVersion"/>
... some fields
    <set name="SalesPosition" lazy="true" inverse="true" cascade="delete" >
        <key>
            <column name="SalesHeaderId"/>
        </key>
        <one-to-many class="SalesPosition"/>
    </set>
</class>

Can anybody give me a tip, what I have to do, that I can only give the key of SalesHeader to the SalesPosition-Entity for persisting (or the SalesHeader-Entity and NHibernate is only using the key).

I use the newest release Version of NHibernate.

Thank you.

Best Regards, Thomas

  • 1 1 Answer
  • 4 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-15T00:16:44+00:00Added an answer on May 15, 2026 at 12:16 am

    If I understand your question correctly, you are attempting to save a SalesPosition instance but you want to just set SalesPosition.SalesHeader.Id instead of setting SalesPosition.SalesHeader to an instance of SalesHeader. You can accomplish this using ISession.Load; this posting explains how it works. Basically, if you know that an entity exists in the database, you can use Load to create a proxy for the object rather than getting it from the database. This is very handy in stateless (web) applications. Usage will be:

    mySalesPosition.SalesHeader = session.Load<SalesHeader>(salesHeaderId);
    session.Flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem to solve: Let's say there is a table A
I have this following problem: I have two tables 1 table for customer bought
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
I have the following problem. I have a table with a few hundred thousand
Greeting! I have the following problem. I have a table with huge number of
I'm new to wicket and stuck with the following problem: I have a table
The problem is the following, I have a table of friendships in my database,
i'm having a problem with my database. I have the folowing: create table book
I'm having the following problem with 2 MySQL tables that have a relation: I
Hi all I have problem with following: foreach (DataRow dr in data.Tables[0].Rows) { string

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.