views:

25

answers:

1

I got issue with bi-directional ManyToMany relationship caching

First side mapping :

        HasManyToMany(x => x.Jobs)
            .Table("ProfileSuggestStoryJob")
            .AsSet()
            .Cascade.None()
            .ParentKeyColumn("ProfileSuggestStoryId")
            .ChildKeyColumn("JobId")
            .Cache.ReadWrite();

Second side mapping :

        HasManyToMany(x => x.SuggestedProfiles)
            .Table("ProfileSuggestStoryJob")
            .AsSet()
            .Cascade.None()
            .ParentKeyColumn("JobId")
            .ChildKeyColumn("ProfileSuggestStoryId")
            .Inverse().Cache.ReadWrite();

The first side is responsible for the insert/update/delete, entites are well stored. But on the second side the cache is not updated, and the collection don't contains the recently added entity.

Without cache, all is working fine ...

A: 

Each side of the relationship has its own cache; NHibernate will not invalidate the cache of the second side because of changes in the first side.

You can use SessionFactory.EvictCollection to invalidate it manually.

Diego Mijelshon