22

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
homaxto
  • 5,428
  • 8
  • 37
  • 53
  • Can you open the class 'ManyToOne' using keyboard shortcut +N? – Boris Pavlović Feb 04 '10 at 12:52
  • Yes I have no problem viewing the class file for ManyToOne. It gives me a location in ejb3-persistence.jar which again is located within JBoss. It also has the method cascade(). – homaxto Feb 04 '10 at 12:55

8 Answers8

33

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

I mean: "File" menu -> 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'.

Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32
Roman
  • 64,384
  • 92
  • 238
  • 332
14

Just got this myself but non of those things were my issue. I downloaded a project from github, then opened in intelli J with the problem after trying to run a junit test.

Solution: Project Structure -> Modules -> 'Project_Name' -> Sources (tab) -> click src folder -> Mark as: Sources

This should highlight src to be blue and all the class files should be the circles with C instead of looking like normal files. Try running a test again and see if that does it.

plosco
  • 891
  • 1
  • 10
  • 18
3

I'm sure, it is too late to answer, but I had to follow a different approach for this error to resolve this issue.

I had to create this as global library and add that library to the module, then only the error is resolved.

Add this as a global library

Then add that library as dependency to the project

Buddha
  • 4,339
  • 2
  • 27
  • 51
1

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 http://jdick.co.uk/blog/wp-content/uploads/2008/12/projectstructure1.jpg

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

had a similar problem ("cannot find class spring...DefaultResourceLoader even though it was in my maven dependencies) and no amount of tweaking of revalidating caches seemed to help. Blowing away my $HOME/.Idea* paths and (basically) starting from scratch fixed it for me. At least for now...

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

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
  • 20,565
  • 5
  • 44
  • 69
0

I was getting the class not found error message when trying to execute a .groovy test class, which referenced a .groovy file (located in the root of the source directory of a submodule - i.e. no packages).

Moving the source file .groovy into a package, fixed the issue for me.

Move:

src/main/groovy/RunMe.groovy

to

src/main/groovy/somePackage/RunMe.groovy
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
0

In intelliJ I got this problem when I built (ctrl+shift+F9) at the file level.

The reason is, I had changes in other files in the same maven project, that were not getting picked.

I solved it by building at the project level (Select the Maven project in intellij and press ctrl+shift+F9)

developer747
  • 15,419
  • 26
  • 93
  • 147