My favourite Hibernate error
… is this one. 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.
The XML
<one-to-many type=”OtherClass”/>
delivers the 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?
Thinking about it, I only just introduced the “type” attribute to the <one-to-many> element in my config. 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.
(Hibernate 3.3.1 - the most current version - although I encountered this error within the first hour of ever using Hibernate in Q1/2006.)

