Chris Kooken
Chris Kooken

Reputation: 33880

NHibernate 1st Level Cache when Item is added to a HasMany Collection

I am creating a new object by adding to to a HasMany collection on ANOTHER object in NHibernate.

When I go to query for that object directly in the same session, it is null. How can I store a child object in a HasMany collection in the 1st level cache. The problem I am having is I need to get the object and do some work on it before everything is committed.

 HasMany(x => x.BehavioralEvents)
     .AsBag()
     .Cascade.SaveUpdate()
     .Inverse()
     .KeyColumn("StudentCaseId")
     .LazyLoad();

BehavioralEvents is an IList and I need to Query for it directly in the same session:

session.Get<BehavioralEvent>(id);

Upvotes: 0

Views: 234

Answers (1)

Jamie Ide
Jamie Ide

Reputation: 49261

You need to Save the new object to make it persistent instead of relying on the cascade settings from the parent object. The cascade will not occur until the session is flushed. I assume you are assigning the ID yourself and not using a generated identifier.

Upvotes: 1

Related Questions