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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:22:53+00:00 2026-05-31T06:22:53+00:00

I’m using (fluent) nhibernate and I’ve run into a little problem. My data model

  • 0

I’m using (fluent) nhibernate and I’ve run into a little problem. My data model is to have a user object with a one-to-many link to another object (I’ll call it Obj1).
Obj1 has a primary key that is external to my application. While I could change it to have it’s own primary key and therefore allow duplicates, it would cause more problems later.

The user can add and remove Obj1’s from their profile whenever they like and the data layer is called immediately when each action is performed. The problem is that if a user adds an Obj1, removes it and then adds it again, then nhibernate gives me a NonUniqueObjectException.

This is because the first Obj1 that is added still seems to be hanging around in the nhibernate session. There seem to be several solutions to this:

  1. Clear session and reload the user obj when updates occur.
  2. From here: nhibernate : a different object with the same identifier value was already associated with the session: 2, of entity: – evict the user object from the session cache after each update.
  3. Re-write the screen that allows the user to manage Obj1’s so that it only calls the data layer when leaving the screen.

1 and 2 are easier but both seem a little hack-ish. 3 seems like the ‘proper’ solution but means I may well come up against the same issue in a more difficult to solve area later on.

So the question is, which is best and why? Are any of these solutions really bad for some reason? (For example, trying to micromanage the nhibernate cache just seems like a bad idea to me.)

Note: strangely enough, by writing this I’ve gone from being totally unsure to pretty convinced that 3 is the best way to go. I’d still be interested to hear other points of view though.

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

    I added a unit test on the repository to reproduce this problem and to my surprise, it worked fine.
    After a few minutes I found the real problem – I was not persisting the delete of Obj1 to the data layer. Once I did that, everything worked fine.

    Oh well, at least it saved me a lot more work.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

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.