views:

494

answers:

3

In IntelliJ I get this weird error when I try to compile.

Cannot find annotation method 'cascade()' in type 'javax.persistence.ManyToOne': class file for javax.persistence.ManyToOne not found

I know, it seems pretty obvious what the problem is, but having spent too much time on this problem I now turn my trust to you!

I use ideaCommunity-9, where I have created a global library for JBoss, which contains all JBoss jars including ejb3-persistence.jar. My module includes this library, and I have moved it to the top of dependencies. No otherwhere in classpath I have a javax.persistence.ManyToOne class, and it also opens up in IntelliJ without problems.
If I open the file where I get the compile error, IntelliJ shows no problems and also navigates to the class file on pressing Ctrl+B.
The code is also build with ant and here it works fine.

Besides the above error I get six others along the same path (name in Table, etc.) - all related to JPA. I also get a message saying "Please file a bug to JDC yada yada yada."

+1  A: 

Isn't that similar to this SO question?

The solution there was to add all JBoss jar (which you did), but also all persistent-related libraries (like Hibernate)

See this JBoss project configuration for example:

alt text

In short, ejb3-persistence.jar might not be the problem here, just a symptom of other elements missing.
Or, if it is the problem, it may be related to the fact that it is not deployed correctly (for the WebApp configuration).

VonC
+3  A: 

Try to tick a checkbox "export" in your dependencies.

I mean: Project Structure -> Modules -> Dependencies, and there you can see libs included to the module. You should also see a checkbox near each lib in column 'Export'. See picture below:

alt text

Roman
I had a similar issue (different annotation same error). This worked for me. Thanks!
A: 

Here's an idea: Maybe you have multiple versions of your jar file. Search your folder hierarchy for the file ejb3-persistence.jar, using a file management tool such as Total Commander. Multiple appearances of the file in your classpath may confuse IntelliJ Idea into not recognizing the proper class in the proper jar.

Yuval F