java 由于“无法在类型 javax.persistence.Table 中找到注释方法 name()”而导致编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4980221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:55:24  来源:igfitidea点击:

Compile error because of "cannot find annotation method name() in type javax.persistence.Table"

javahibernateintellij-ideacompiler-errorsjpa-2.0

提问by ?zbek

My project is not compiling, and giving these errors:

我的项目没有编译,并给出以下错误:

Information: D:\projects\gre\com\site\core\domain\Employee.class: warning: Cannot find annotation method 'schema()' in type 'javax.persistence.Table': class file for javax.persistence.Table not found.
Information:D:\projects\gre\com\site\core\domain\Employee.class: warning: Cannot find annotation method 'name()' in type 'javax.persistence.Table': class file for javax.persistence.Table not found.
Information:D:\projects\gre\com\site\core\domain\Employee.class: warning: Cannot find annotation method 'fetch()' in type 'javax.persistence.ManyToOne': class file for javax.persistence.ManyToOne not found.
Information:An Exception has occurred in the compiler(1.6.0_22).Please file a bug at the Java Developer Conncetion(http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
Information:com.sun.tools.javac.code.Symbol$CompilationFailure:class for javax.persistence.FetchType not found
Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Error:compiler internal error. Process terminated with exit code 4

信息:D:\projects\gre\com\site\core\domain\Employee.class:警告:在类型“javax.persistence.Table”中找不到注释方法“schema()”:javax.persistence.Table 的类文件未找到。
信息:D:\projects\gre\com\site\core\domain\Employee.class:警告:在类型“javax.persistence.Table”中找不到注释方法“name()”:javax.persistence.Table 的类文件未找到。
信息:D:\projects\gre\com\site\core\domain\Employee.class:警告:在类型“javax.persistence.ManyToOne”中找不到注释方法“fetch()”:javax.persistence.ManyToOne 的类文件未找到。
信息:编译器(1.6.0_22) 中发生异常。请在检查Bug Parade 中的重复项后在Java Developer Conncetion(http://java.sun.com/webapps/bugreport) 提交错误。在您的报告中包括您的程序和以下诊断。谢谢你。
信息:com.sun.tools.javac.code.Symbol$CompilationFailure:未找到 javax.persistence.FetchType 的类
信息:编译完成,出现 1 个错误和 0 个警告
信息:1 个错误
错误:编译器内部错误。进程以退出代码 4 终止

I'm using IntelliJ Idea 9, properly attached hibernate-jpa-2.0-api-1.0.0.Final.jar
I've invalidated the cache, deleted out/war folders but still having an error at the compile time.

我正在使用 IntelliJ Idea 9,正确附加hibernate-jpa-2.0-api-1.0.0.Final.jar
我已经使缓存无效,删除了 out/war 文件夹,但在编译时仍然有错误。

采纳答案by brent777

I use IntelliJ as well and hibernate-jpa-2.0-api-1.0.0.Final.jar and javax/persistence/Table.class and javax/persistence/ManyToOne.class are definitely in this JAR.

我也使用 IntelliJ,并且 hibernate-jpa-2.0-api-1.0.0.Final.jar 和 javax/persistence/Table.class 和 javax/persistence/ManyToOne.class 肯定在这个 JAR 中。

I can only think that the JAR is not in your classpath. Where have you placed this JAR? What are you using to try compile your code? Are you certain it is in your classpath?

我只能认为 JAR 不在您的类路径中。你把这个 JAR 放在哪里了?你用什么来尝试编译你的代码?你确定它在你的类路径中吗?

回答by AlexR

Unfortunately I do not have my dev. environment here but as far as I remember hibernate jar does not necessarily contain the JPA stuff, so you have to add the persistence.jar to your classpath.

不幸的是,我没有我的开发人员。环境在这里,但据我所知,hibernate jar 不一定包含 JPA 的东西,所以你必须将 persistence.jar 添加到你的类路径中。

BTW try to use maven as a build tool and forget about resolving dependencies between third party libraries.

顺便说一句,尝试使用 maven 作为构建工具而忘记解决第三方库之间的依赖关系。