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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:46:15+00:00 2026-05-25T13:46:15+00:00

I have a many-to-many relationship between two entities. As part of a batch process,

  • 0

I have a many-to-many relationship between two entities. As part of a batch process, I am creating a large number of these entities and relating them together. This is using an IStatelessSession.

I am using NHibernate 3.0.

Entities:

class Entity1
{
    ICollection<Entity2> Entities { get; set; }
}

class Entity2
{
    ICollection<Entity1> Entities { get; set; }
}

Basically the batch code looks something like:

var entity1 = new Entity1();  
var entity2 = new Entity2();  

entity1.Entities.Add(entity2);  
entity2.Entities.Add(entity1);  

Session.Insert(entity1);   // IStatelessSession.Insert
Session.Insert(entity2);

The two entities are correctly persisted, however the relationship table between them is not updated with the relationship between the two entities.

I understand that this has to do with the fact that stateless sessions don’t track the objects. But how would I go about achieving many-to-many persistence?

  • 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-25T13:46:16+00:00Added an answer on May 25, 2026 at 1:46 pm

    Collections are ignored by stateless sessions. You should use regular ISession and call ISession.Clear at a reasonable interval (say every 500 objects). This way 1st level cache will not get bloated and you will have decent performance.

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

Sidebar

Related Questions

I have a many-to-many relationship between the two entities called events and artists, both
I have a many-to-many relationship defined between two entities using an association table and
I have a one to many entity relationship between two entities: EntityP (Parent) <-->>
I have a many-to-many relationship between two entities - Media and MediaCollection. I want
I have two entities Foo and Bar with a Many to Many relationship between
I've got two entities with a one-to-many relationship between them. The entity that holds
I have two entities, Account and Subscription with a many-to-many association between them. I
Suppose i have a one to many relationship between two model entities Entity One
I have a many-to-many relationship between two tables, let's say Friends and Foods. If
Is it possible to have a many to many relationship between two tables, and

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.