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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:46:33+00:00 2026-05-27T17:46:33+00:00

While adding post to the post repository an exception occurs with the following message:

  • 0

While adding post to the post repository an exception occurs with the following message: not null property references a null or transient value Category.

[Test]
public void PostInsertion()
{
    var category = new Category 
    {
        Title = "Programming",
        Description = "Programming"
    };
    var post = new Post
    {
        AuthorUrl = "some url",
        Category = category,
        Content = "some content",
        Feedbacks = new HashedSet<Feedback>(),
        Timestamp = DateTime.Now,
        Title = "some title"
    };

    var postRepository = new Repository<Post>(this.sessionFactory);
    postRepository.Add(post);
}

What does it mean?

EDIT: Post entity definition

[Serializable]
public class Post : Entity<Post>
{
    public Post()
    {
        this.Feedbacks = new HashedSet<Feedback>();
    }

    public virtual String Title { get; set; }
    public virtual String Content { get; set; }
    public virtual DateTime Timestamp { get; set; }
    public virtual Byte[] Thumbnail { get; set; }
    public virtual Byte[] AuthorImg { get; set; }
    public virtual String AuthorUrl { get; set; }
    public virtual Category Category { get; set; }
    public virtual ISet<Feedback> Feedbacks { get; set; }

    public virtual void AddFeedback(Feedback feedback)
    {
        this.Feedbacks.Add(feedback);
    }
}

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-27T17:46:34+00:00Added an answer on May 27, 2026 at 5:46 pm

    That exception was thrown because NHibernate tried to add a reference to a Category that was not persisted on the database. In you example you are creating a new Category, so you have two options:

    1. Save the Category before saving the Post;
    2. Change the Post mapping and make it cascade save the associations;

    For the second option, if you are using Xml mapping, then you’ll need something like:

    <many-to-one name="Category" column="CategoryId" cascade="all"/>
    

    If you are using Fluent NHibernate, then it’ll be:

    References(x => x.Category, "CategoryId").Cascade.All(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following exception while adding data into database: org.hibernate.HibernateException: The database
Preface: This has become a quite a long post. While I'm not new to
Any ideas why the following code is not adding anything into the database once
While adding the parameters to get/post request they need to be encoded in application/x-www-form-urlencoded
While adding two language code files i.e. C# and VB.NET to App_Code, got an
I can't view header in JTable while adding it into a JFrame.. String[] col={Name,ID,Marks};
While going through university and from following the development of SO, I've heard a
I'm getting the following exception trying to pass an object through wcf: There was
I choose not to post this on SeverFault b/c that site seems to be
I have a list and i am adding a value using add(int,Object) method but

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.