Hibernate error means the complete opposite of what it says, due to wording error

The following XML:

<one-to-many type="OtherClass"/>

delivers the following error:

Error parsing XML: Attribute "type" must be declared for element type "one-to-many".

This looks like a perfectly self-explanatory error, however looking at the file, the element does have a "type" attribute. What should one do?

At the time I first encountered this, I had only just introduced the "type" attribute. What happens if I change the attribute name to "fsdjkfdk"?

<one-to-many fsdjkfdk="OtherClass"/>

The error is now:

Error parsing XML: Attribute "fsdjkfdk" must be declared for element type "one-to-many".

What the error means is that the attribute must not be declared, as opposed to must.

It's amusing to read even people on the Hibernate team get confused by this error, and can't find a solution.

I've wasted many an hour searching for the cause of this. And it's one you're likely to run into pretty quickly when you try to write your first Hibernate configuration file.

(Hibernate 3.3.1 – the most current version – although I encountered this error within the first hour of ever using Hibernate in Q1/2006.)

P.S. I recently created a nerdy privacy-respecting tool called When Will I Run Out Of Money? It's available for free if you want to check it out.

This article is © Adrian Smith.
It was originally published on 10 Jun 2009
More on: FAIL | Hibernate | Words & Language