Many-to-Many Relationship mapping does not trigger the EventListener OnPostInsert or OnPostDelete Ev
- by san
I'm doing my auditing using the Events listeners that nHibernate provides. It works fine for all mappings apart from HasmanyToMany mapping. My Mappings are as such:
Table("Order");
Id(x => x.Id, "OrderId");
Map(x => x.Name, "OrderName").Length(150).Not.Nullable();
Map(x => x.Description, "OrderDescription").Length(800).Not.Nullable();
Map(x => x.CreatedOn).Not.Nullable();
Map(x => x.CreatedBy).Length(70).Not.Nullable();
Map(x => x.UpdatedOn).Not.Nullable();
Map(x => x.UpdatedBy).Length(70).Not.Nullable();
HasManyToMany(x => x.Products)
.Table("OrderProduct")
.ParentKeyColumn("OrderId")
.ChildKeyColumn("ProductId")
.Cascade.None()
.Inverse()
.AsSet();
Table("Product");
Id(x => x.Id, "ProductId");
Map(x => x.ProductName).Length(150).Not.Nullable();
Map(x => x.ProductnDescription).Length(800).Not.Nullable();
Map(x => x.Amount).Not.Nullable();
Map(x => x.CreatedOn).Not.Nullable(); ;
Map(x => x.CreatedBy).Length(70).Not.Nullable();
Map(x => x.UpdatedOn).Not.Nullable();
Map(x => x.UpdatedBy).Length(70).Not.Nullable();
HasManyToMany(x => x.Orders)
.Table("OrderProduct")
.ParentKeyColumn("ProductId")
.ChildKeyColumn("OrderId")
.Cascade.None()
.AsSet();
Whenever I do an update of an order (Eg: Changed the Orderdescription and deleted one of the products associated with it) It works fine as in it updated the order table and deletes the row in the orderproduct table. the event listener that I have associated with it captures the update of the order table but does NOT capture the associated delete event when the orderproduct is deleted. This behaviour is observed only in case of a ManyTomany mapped relationships. Since I would also like audit the packageproduct deletion, its kind of an annoyance when the event listener aren't able to capture the delete event. Any information about it would be greatly appreciated.