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

By Adrian Smith10 Jun 2009200 words1 mins to read

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.)

This article was written by Adrian Smith on 10 Jun 2009

Follow me: Facebook | Twitter | LinkedIn | Email

More on: FAIL | Hibernate | Words & Language