Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate LazyInitializationException.. How to prevent?

Tags:

nhibernate

I'm getting the following error on our production web server:

NHibernate.LazyInitializationException
: 
Initializing[Domain.Entities.AudienceTypes.Region#4]-failed to lazily initialize a 
collection of role: Domain.Entities.AudienceTypes.Region.PeerGroups, 
no session or session was closed

which isn't good. The only way to get the application working again is to reset IIS, which isn't really an option. What does this mean? How can I prevent it?

like image 996
DaveDev Avatar asked Dec 08 '10 15:12

DaveDev


1 Answers

To avoid this issue you need to change reference for PeerGroups in your Region mapping class as below

References(x => x.PeerGroupId, "PeerGroupId").Fetch.Join();

Adding Fetch.Join() will prevent LazyInitializationException.

like image 171
Arkadas Kilic Avatar answered Oct 22 '22 21:10

Arkadas Kilic