Tuesday, June 21, 2011

Annotation Failures With Hibernate & Netbeans

If you receive error messages indicating that certain class files for annotation cannot be found, such as:

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.hibernate.annotations.Sort not found

even though the IDE has allowed you to import the annotation and has not thrown any errors until you attempt to build it, your problem is related to inter-module dependencies. Don't ask me why, but if module C uses an annotation "@Sort", via depending on (for example) your hibernate wrapper module, some, or most probably all, of your other modules in the tree (A & B) also need to depend on the hibernate wrapper module otherwise you'll get this error.

I say "some, or most probably all" because I haven't the time or inclination to do a thorough search to find out which module was causing the problem, I just know it was solved as soon as I added the library to all of my modules...

You also need to make sure you've exported all of the appropriate packages in your wrapped libraries, as this can sometimes cause similar problems.