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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:22:56+00:00 2026-05-19T12:22:56+00:00

We have implemented our domain model using the accountability pattern, which we are trying

  • 0

We have implemented our domain model using the accountability pattern, which we are trying to persist using NHibernate with fluent NHibernate to define the maps.

Effectively we have 3 entities, Accountability (used to define the relationship between parties), Party (used to define the party, i.e. contact, person, business etc) and the AccountabilityType (used to specify the accountability relationship, i.e. “Belongs To”, “Owned By” etc)

I am running into a brick wall in terms of defining the maps.

The ERD looks like this (aaarrgg new users cannot post images, life and its little challenges):

I hope from the maps you will be able to figure out the ERD.

The entities are defined as follows (they have been dumbed down for testing):

public class AccountabilityType
{
    public virtual string Id { get; set; }

    public override int GetHashCode()
    {
        return Id.GetHashCode();
    }

    public override bool Equals(object obj)
    {
        var other = obj as AccountabilityType;
        if (other == null)
            return false;
        return other.GetHashCode() == GetHashCode();
    }
}


public class Accountability
{
    #region Properties

    public virtual Guid Id { get; set; }

    public virtual Party Parent { get; set; }

    public virtual Party Child { get; set; }

    public virtual AccountabilityType Type { get; set; }

    #endregion

    #region Methods

    public override int GetHashCode()
    {
        return Type.GetHashCode() ^ Parent.GetHashCode() ^ Child.GetHashCode();
    }

    public override bool Equals(object obj)
    {
        var other = obj as Accountability;
        if (other == null)
            return false;
        return other.GetHashCode() == GetHashCode();
    }

    #endregion
}

public class Party
{
    public Party()
    {
        ParentAccountabilities = new List<Accountability>();
        ChildAccountabilities = new List<Accountability>();
    }

    #region Properties

    public virtual Guid Id { get; set; }

    public virtual string Name { get; set; }

    public virtual string Type { get; set; }

    // Exposed for persistence, Hackity Hack, dont hate the player hate the game
    public virtual IList<Accountability> ParentAccountabilities { get; set; }

    // Exposed for persistence, Hackity Hack, dont hate the player hate the game
    public virtual IList<Accountability> ChildAccountabilities { get; set; }

    #endregion

    #region Overrides

    public override int GetHashCode()
    {
        return Type.GetHashCode() ^ Name.GetHashCode();
    }

    public override bool Equals(object obj)
    {
        var other = obj as Party;
        if (other == null)
            return false;
        return other.GetHashCode() == GetHashCode();
    }

    #endregion
}

And finally the fluent maps as follows:

public class AccountabilityTypeMap : ClassMap<AccountabilityType>
{
    public AccountabilityTypeMap()
    {
        Id(p => p.Id).GeneratedBy.Assigned();
    }
}

public class AccountabilityMap : ClassMap<Accountability>
{
    public AccountabilityMap()
    {
        Id(p => p.Id).GeneratedBy.Guid();

        References(p => p.Parent, "ParentId").Cascade.None();

        References(p => p.Child, "ChildId").Cascade.All();

        References(p => p.Type, "AccountabilityTypeId").Cascade.None();
    }
}

public class PartyMap : ClassMap<Party>
{
    public PartyMap()
    {
        Id(p => p.Id).GeneratedBy.Assigned();

        Map(p => p.Name);

        Map(p => p.Type);

        HasManyToMany(p => p.ChildAccountabilities)
            .Table("Accountability")
            .ParentKeyColumn("ChildId")
            .ChildKeyColumn("ParentId")
            .Cascade.All();

        HasManyToMany(p => p.ParentAccountabilities)
            .Table("Accountability")
            .ParentKeyColumn("ParentId")
            .ChildKeyColumn("ChildId")
            .Cascade.None()
            .Inverse();
    }
}

The entities are persisting to the DB, however NHibernate throws an error on session.Flush() and the error indicates that it is trying to insert an Accountability entity with a NULL id. This is first of all impossible since the Id is a non nullable Guid, and I have been through the object model to ensure that there is no object with a null/empty id.

Any suggestions would be most appreciated 🙂

Thanks

  • 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-19T12:22:57+00:00Added an answer on May 19, 2026 at 12:22 pm

    It seems I got the mapping confused. I am not dealing with ManyToMany mapping since I am modeling the bridge table in my domain. The mapping should look like this.

    public class AccountabilityTypeMap : ClassMap<AccountabilityType>
    {
        public AccountabilityTypeMap()
        {
            Id(p => p.Id).GeneratedBy.Assigned();
        }
    }
    
    public class AccountabilityMap : ClassMap<Accountability>
    {
        public AccountabilityMap()
        {
            Id(p => p.Id).GeneratedBy.Guid();
    
            References(p => p.Parent, "ParentId").Cascade.None();
    
            References(p => p.Child, "ChildId").Cascade.All();
    
            References(p => p.Type, "AccountabilityTypeId").Cascade.None();
        }
    }
    
    public class PartyMap : ClassMap<Party>
    {
        public PartyMap()
        {
            Id(p => p.Id).GeneratedBy.Guid();
    
            Map(p => p.Name);
    
            Map(p => p.Type);
    
            HasMany(p => p.ChildAccountabilities)
                .KeyColumn("ParentId")
                .Inverse()
                .Cascade.All();
    
            HasMany(p => p.ParentAccountabilities)
                .KeyColumn("ChildId")
                .Inverse()
                .Cascade.All();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our desktop application, we have implemented a simple search engine using an inverted
We have implemented JUnit4 in our application which uses Spring core & JPA with
I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and
We have implemented a popup window as a modal dialog using the IE method:
My team is in the process of designing a domain model which will hide
I've implemented the repository pattern on the data access layer of our current service
We have implemented a general purpose deep copy mechanism using serialization. import java.io.*; public
I have implemented what I thought was a pretty decent representation of MVC in
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have implemented a python webserver. Each http request spawns a new thread. I

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.