Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cascading collections using NHibernate StatelessSession

What is the proper way to bulk insert entities which contain collections of other entities (a HasMany mapping), using stateless sessions?

E.g. Parent class is mapped like this:

class ParentMap : ClassMap<Parent>
{
    public ParentMap()
    {
        Id(x => x.Id)
           .GeneratedBy.Increment();

        HasMany(x => x.ChildNodes)
           .KeyColumns.Add("Parent_id")
           .Cascade.All();
    }  
}

Stateless session ignores the Cascade option, so child nodes are not persisted automatically. I could iterate through the collection myself, but then I cannot set the relation, because Parent_id column does not exist as a property I could write to.

Am I missing something?

like image 261
Groo Avatar asked Nov 25 '10 11:11

Groo


1 Answers

You have to either create the Parent property in the child class, or use a stateful session.

like image 102
Diego Mijelshon Avatar answered Sep 18 '22 03:09

Diego Mijelshon