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

  • Home
  • SEARCH
  • 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 62373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:27:57+00:00 2026-05-10T18:27:57+00:00

I have an existing database with the table Transactions in it. I have added

  • 0

I have an existing database with the table Transactions in it. I have added a new table called TransactionSequence where each transaction will ultimately have only one record. We are using the sequence table to count transactions for a given account. I have mapped this as a one-to-one mapping where TransactionSequence has a primary key of TransactionId.

The constraint is that there is an instead of trigger on the transaction table does not allow updates of cancelled or posted transactions.

So, when the sequence is calculated and the transaction is saved, NHibernate tries to send an update on the transaction like ‘UPDATE Transaction SET TransactionId = ? WHERE TransactionId = ?’. But this fails because of the trigger. How can I configure my mapping so that NHibernate will not try to update the Transaction table when a new TransactionSequence table is inserted?

Transaction mapping:

<class name='Transaction' table='Transaction' dynamic-update='true' select-before-update='true'>     <id name='Id' column='ID'>         <generator class='native' />     </id>      <property name='TransactionTypeId' access='field.camelcase-underscore' />     <property name='TransactionStatusId' column='DebitDebitStatus' access='field.camelcase-underscore' />      <one-to-one name='Sequence' class='TransactionSequence' fetch='join'                  lazy='false' constrained='false'>           </one-to-one> </class> 

And the sequence mapping:

<class name='TransactionSequence' table='TransactionSequence' dynamic-update='true'>     <id name='TransactionId' column='TransactionID' type='Int32'>         <generator class='foreign'>             <param name='property'>Transaction</param>         </generator>     </id>      <version name='Version' column='Version' unsaved-value='-1' access='field.camelcase-underscore' />      <property name='SequenceNumber' not-null='true' />      <one-to-one name='Transaction'                  class='Transaction'                  constrained='true'                  foreign-key='fk_Transaction_Sequence' />  </class> 

Any help would be greatly appreciated…

  • 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. 2026-05-10T18:27:57+00:00Added an answer on May 10, 2026 at 6:27 pm

    One to one mapping in nhibernate doesn’t work the way you think it does. It’s designed so that you have two classes, which when persisted to their corresponding tables have the same primary keys.

    However you can make it work, but it’s not pretty. I’ll show you how then offer up some alternatives:

    In your Transaction hbml:

    <one-to-one name='Sequence' class='TransactionSequence' property-ref='Transaction'/> 

    In your Sequence html:

    <many-to-one name='Transaction' class='Transaction' column='fk_Transaction_Sequence' /> 

    This should do what you want it to do. Note the property-ref.

    The next question you’re going to post on is going to ask how you get lazy loading on one-to-one associations. The answer is, you can’t… well you can, but it probably won’t work. The problem is that you have your foreign key on the sequence table, which means that nhibernate has to hit the database to see if the target exists. Then you can try playing around with constrained=’true/false’ to see if you can persuade it to lazily load the one-to-one association.

    All in all, it’s going to result in a total waste of your time.

    I suggest either:

    1. Have two many-to-one associations.
    2. Have a many-to-one association with a collection on the other end.

    This will save you a lot of headaches in the long run.

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

Sidebar

Related Questions

I have an existing database of a film rental system. Each film has a
I have an existing database with a users table and questions/answers table. I'd like
I have 2 databases, and I want to transport an existing table containing a
I have an existing database that has some testing data into and I'm interested
I currently have an existing database and I am using the LINQtoSQL generator tool
If I have an existing database, I want to be able to automatically code
I have an existing SQL Server 2005 database that runs our accounting/inventory application. We
I have some existing code that retrieves data from a database using ADO.NET that
I have a script that appends some rows to a table. One of the
The goal: refresh database from XML data The process: Start transaction Delete all existing

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.