ActiveRecord / NHibernate: handling lazy collections in persistent context

My web app (MonoRail, Windsor, ActiveRecord) has an import service and one or more bootable readers. When, for example, a file is deleted in a directory, the reader parses the file, transfers the data to the service, which updates and / or creates objects through the repositories. The problem is that these Startable services live outside the scope of the request (where the SessionScope from Begin to End is), so when the service encounters a lazy collection, there is no SessionScope to help it do its magic. Cue LazyInitializationException :).

Any ideas how to solve this problem? Perhaps using an interceptor to create and delete a SessionScope around a data method? Equip storage with methods that do targeted sampling? I want the services not to know ActiveRecord because my dependency paranoia says we could use a different persistence mechanism one day.

+1


source to share


1 answer


You already answered it:



using an interceptor to create and place the SessionScope around the method that handles the data

0


source







All Articles