Ayende’s NHibernate.Generics is truly an incredible advance in supporting generic collections with NHibernate, and solving the two-way relationship problem at the same time. I switched all my projects to use it because it made the code so much prettier than my own MyNHibernateContrib project.
However, after running into several unforeseen issues, I’ve been forced to revert all my code back to MyNHibernateContrib for my largest projects. The code may look a little uglier, but it works quite well. Here are the issues I’ve had in trying Ayende’s library. He already knows about some of these and warns about them on this blog, but the extent to which they cause problems were greater than I anticipated based on his web page.
- As yet unpersisted entities added to a lazy and not yet loaded collection do not show up in the collection at all. And cascade save from the collection to the entity never happens! So my tens of thousands of lines of code written to take advantage of cascade save has bugs ridden through it suddenly, as entities are not saving all over the place.
- When I try to solve the the previous problem by disabling his extra lazy-loading feature for collections, I get lazy-loading exceptions thrown from NHibernate that I just haven’t been able to solve.
- List collection persistence seems shaky (indexes within the list randomly changed).
- Map collection (Dictionary) persistence is non-existent.
- NHibernate collection cache doesn’t match added contents, when an entity is added to an unloaded collection with something like apple.Tree = someTree; someTree.Apples, when loaded in some later ISession, does not include the apple, even when reloaded. The NH cache must be refreshed for it to ever show up.
I hope Ayende and/or the NHibernate team can fix these issues so I can get back to pretty code. I applaud Ayende’s work, and I am still using his library on my smaller projects. Keep up the good work, Ayende! And if anyone (including myself) has some time to help with these bugs or implementation holes, by all means, please contribute to his project.