Fix for NH-2285

I fixed https://nhibernate.jira.com/browse/NH-2285 and added some tests