NHibernate error messages

November 30th, 2007

Those are just from today:

1. Can't write to a readonly object

No meaningful information on the call stack, not a single clue. Would it hurt to tell which object is marked as ReadOnly?

2. Could not instantiate cache implementation
Inner exception: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

wtf?

3. StaleObjectException

Note that I'm not using version/timestamp. Turns out that there was a call to update when it should be a call for Create.


Ayende recently blogged about Castle style errors. At least the more important ones try to tell you what happened, why and how to fix it. I decided upon this path due to two things

1 - When I used to work with Visual C++, most error messages included a clue "did you forget to turn option foobar?". Those were very helpful.

2 - In the early days of Castle I was setting up a project for a new client and everything collapsed. I had only an odd exception that didn't tell much. From that day on I vowed to never let that happen again. Can you imagine looking clueless in front of a client dealing with a project that you're supposed to know everything about?

NHibernate goes in other direction. Maybe they want that every user digs on the code base, become NHibernate hackers, or they just want to challenge you to make your life more interesting. I guess next version will include riddles with every error message: "Stale object exception: what gets wet as it dries?"

6 Responses to “NHibernate error messages”

Joe Says:

A towel! Do I win something or what?

Nate Kohari Says:

Very, very true. Castle’s exception messages are head and shoulders above the rest. I was surprised to see how bad some NHibernate messages are.

Also, a towel. :)

Ayende Rahien Says:

First, allow me to apologize for those errors.

1/ The first error happened not because an object was read only, but because it was marked as read only for caching. I changed the exception to make it clear that it comes from the read only cache and included the object type there as well.
2/ That error occurs when you have enabled the query cache, but you did not select a cache provider, I have changed the exception to read:
Second-level cache is enabled, but no cache provider was selected.
Please use hibernace.cache.cacheprovider to specify a cache provider such as SysCacheProvider

Ayende Rahien Says:

Sorry, got cut off.

3/ That error doesn’t happen only when you have version/timestamp, but also when you have enabled optimistic locking based on the properties values.
I assume that you have this enabled, otherwise you will get a row count exception.

hammett Says:

Thanks, Ayende. But no, I dont have optimistic locking enabled. Honestly, I wasn’t even aware that such thing existed.

Ayende Rahien Says:

Can you create a test case or it?

Leave a Reply