Yoann. B
Yoann. B

Reputation: 11143

NHibernate Bi-directional ManyToMany Relationship Caching Issue

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 ...

Upvotes: 3

Views: 356

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

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.

Upvotes: 3

Related Questions