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 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 a new database table called schools . I have an existing database
I have an existing database with tables which each have 4 partitions (there are
I have an existing database in mysql. One of my tables has discontinuous ids.
I have an existing database with a number of columns. One of these is
So I have an existing database with a Users table and an Airports table
I have an existing database with a users table and questions/answers table. I'd like
Hi I have an existing database with a table with 30 fields, I want
I have an existing database with users and administrators in different tables. I am
I have an existing database(myDatabse) that I created with Microsoft Sql Managenent studio and
I have an existing database containing some pictures in blob fields. For a web

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.