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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:42:15+00:00 2026-05-11T01:42:15+00:00

any help you can give is very gratefully accepted. I’ve been looking at this

  • 0

any help you can give is very gratefully accepted. I’ve been looking at this problem over and over and cannot seem to find the solution. Its probably staring in me in the face 🙁

I have the following class with a list of parents and children to be persisted in a Hierarchy table.

class Item   {       public virtual int Id {get;set;}       public virtual List`<Item`> Parents {get;set;}       public virtual List`<Item`> Children {get;set;}   }   

In the hibernate settings, I have:

<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'   assembly='Pl.Components' namespace='Pl.Components'`>       <class name='Pl.Components.Item, Pl.Components' table='Item'>           <id name='Id' type='Int32'  column='Id' >               <generator class='identity' />           </id>           <bag name='Parents' lazy='true' table='Hierarchy' cascade='save-update'>               <key column='ChildId'/>               <many-to-many class='Item' column='ParentId' />           </bag>           <bag name='Children' lazy='true' table='Hierarchy' cascade='delete'>               <key column='ParentId'/>               <many-to-many class='Item' column='ChildId'/>           </bag`>       </class>   </hibernate-mapping>   

This is causing duplicate keys in the Hierarchy table as the key pairs are inserted for both the child and the parent.

Is there any solution to this other than persisting parent hierarchy and children hierarchy in separate tables?

  • 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-11T01:42:16+00:00Added an answer on May 11, 2026 at 1:42 am

    You need to mark one of the bags as inverse=’true’. See http://www.hibernate.org/hib_docs/nhibernate/html/collections.html#collections-bidirectional

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

Sidebar

Related Questions

Been looking around a bit and I can't seem to find any help on
I can't seem to find any help on this but under the Net tab
I'm a very confused student. Any help you can give is appreciated. I'm unsure
Thanks for any help in advance, I can't wrap my SQL skills around this
I can't seem to figure out how to inject a disabled element. Any help
I need some drawings in my tableview. How can i do this. Any help
I can't get my progress bar to work. Any help is much appreciated! Here's
I'm getting an EXC_BAD_ACCESS but just can't work out why, any help would be
Basic question.. had to ask. Any help will be appreciated. Q: Why can't I
I want to disable camera flash. How can I do that? Any help will

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.