NHibernate IStatelessSession and many-to-many relationships

I have a many-to-many relationship between two objects. As part of the batch process, I create a large number of these objects and link them together. It is used 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 this:

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

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

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

Two objects are correctly saved, however, the table of relations between them is not updated using the relationship between two objects.

I understand that this is because stateless sessions do not track objects. But how can I achieve many-to-many perseverance?

+3
source share
1 answer

. ISession ISession.Clear (, 500 ). , , .

+1

Source: https://habr.com/ru/post/1783800/


All Articles