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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:57:51+00:00 2026-05-15T17:57:51+00:00

I am using Nhibernate with Fluent, to persist a SQL Server 2008 express database

  • 0

I am using Nhibernate with Fluent, to persist a SQL Server 2008 express database in a business application.

I have a class named Receipt which contains a list with many objects named ReceiptItems.
The user can create a receipt, add Receiptitems to it, and edit it as long as its not marked Finished.
This part works well and saves to the db correctly.
Now for the problem:

I also have a trigger on the sql table Receipt, that fires if the inserted.Finished is true.
The trigger fetches new prices from the “supplier table”, and updates the prices for all ReceiptItems,
in the ReceiptItems table.

When calling
session.SaveorUpdate(value)
and then
transaction.Commit()

the latter causes the exception:
StaleObjectStateException
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) in ReceiptItems

Removing the trigger ofcourse fixes the problem, but i need it to update the prices. Is there any way for nhibernate to ignore the
error, and refresh its cache after the trigger fires?

straightforward class example definitions with Fluent mappings:

 public class Receipt
    {

        public Receipt() { }
        /// <summary>Identificator/// </summary>
        public virtual int Id { get; private set; }
        /// <summary> if finished true, cant edit data/// </summary>
        public virtual Boolean Finished { get; set; }
        /// <summary>Items of this Receipt/// </summary>
        public virtual IList<ReceiptItems> Items{ get; set; }
    }

    /// <summary>Mapping for NHibernate Fluent/// </summary>
    public class ProdajaMap : ClassMap<Prodaja>
    {

        public ReceiptMap()
        {
            Table("Receipt");
            OptimisticLock.All();
            DynamicUpdate();
            Id(x => x.Id);
            Map(x => x.Finished);
            HasMany<ReceiptItems>(x => x.Items).AsBag().KeyColumn("Receipt_ID");
        }
    }

public class ReceiptItem
    {

        public ReceiptItem() { }

        public virtual int Id { get; private set; }
        /// <summary>Id of the Receipt/// </summary>
        public virtual int Receipt_ID{ get; set; }

        /// <summary>Supplier price/// </summary>
        public virtual decimal Price{ get; set; }
        /// <summary>Supplier discount/// </summary>
        public virtual decimal Discount { get; set; }
    }

    /// <summary>Mapping for NHibernate Fluent/// </summary>
    public class ReceiptItemMap : ClassMap<ReceiptItem>
    {
        public ReceiptItemMap()
        {
            Table("ReceiptItems");
            OptimisticLock.All();
            DynamicUpdate();
            Id(x => x.Id);
            Map(x => x.Receipt_ID).Column("Receipt_ID");
            Map(x => x.Price);
            Map(x => x.Discount );

        }
    }

Thank you very much !

UPDATE:

I’ve found a nhibernate property, which does exactly what i need, as the Price and Discount values have to be generated by the trigger:

5.6. Generated Properties Generated properties are properties which have
their values generated by the
database. Typically, Hibernate
applications needed to refresh objects
which contain any properties for which
the database was generating values.
Marking properties as generated,
however, lets the application delegate
this responsibility to Hibernate.
Essentially, whenever Hibernate issues
an SQL INSERT or UPDATE for an entity
which has defined generated
properties, it immediately issues a
select afterwards to retrieve the
generated values.

Properties marked as generated must
additionally be non-insertable and
non-updateable.

As im new at this.., does the last sentance mean, that i can’t insert or update the values with nhibernate?

  • 1 1 Answer
  • 1 View
  • 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-15T17:57:51+00:00Added an answer on May 15, 2026 at 5:57 pm

    Use SET NOCOUNT ON in the trigger to suppress (xx rows affected) “dummy” result sets from trigger processing.

    Example SO question: TooManyRowsAffectedException with encrypted triggers

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

Sidebar

Related Questions

I have a WPF Application using Fluent NHibernate 1.0 RTM and System.Data.SQLite 1.0.65 that
I have been unable to persist a nullable enum using NHibernate with Fluent NHibernate
I am using NHibernate with fluent mapping. I have the following scenario: public class
I've a rather large domain-model that persists using fluent NHibernate to MS SQL Server
Using NHibernate and Fluent Mappings. We have a property (Groupable) of a class (GroupAssignment)
I'm using NHibernate + Fluent to handle the database in my application. So far
I am using NHibernate/Fluent NHibernate in an ASP.NET MVC app with a MySQL database.
I'm using Fluent NHibernate auto mapping. I need to access more than one database
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
Currently I'm using Fluent NHibernate to generate my database schema, but I want the

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.