使用hibernate创建插入操作,我收到以下错误?

时间:2016-06-24 07:09:43

标签: java spring hibernate model-view-controller

使用hibernate创建插入操作,我收到以下错误 线程中的异常

"main" java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext.<init>(Lorg/hibernate/boot/spi/ClassLoaderAccess;)V
    at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(JPAMetadataProvider.java:66)
    at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.generateDefaultReflectionManager(MetadataBuilderImpl.java:742)
    at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:715)
    at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:127)
    at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:654)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)
    at com.pojoclass.main.InsertEmp.main(InsertEmp.java:20)          

jar文件列表

C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\antlr-2.7.7.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\cdi-api-1.1-PFD.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\classmate-1.3.0.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\dom4j-1.6.1.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\el-api-2.2.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\geronimo-jta_1.1_spec-1.1.1.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\hibernate-annotations.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\hibernate-commons-annotations-5.0.1.Final.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\hibernate-core-5.2.0.Final.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\hibernate-jpa-2.1-api-1.0.0.Final.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\jandex-2.0.0.Final.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\javassist-3.20.0-GA.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\javax.inject-1.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\jboss-logging-3.3.0.Final.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\jsr250-api-1.0.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\mysql-connector-java-5.1.38-bin.jar
C:\Users\rbhupatiraju\Downloads\hibernate-release-5.2.0.Final\lib\required\hibernate-commons-annotations-3.0.0.ga.jar

2 个答案:

答案 0 :(得分:1)

类路径中有不正确的库。

您不需要此库

hibernate-release-5.2.0.Final\lib\required\hibernate-annotations.jar 

hibernate-release-5.2.0.Final\lib\required\hibernate-commons-annotations-3.0.0.ga.jar

我建议您使用Maven或Gradle构建。

答案 1 :(得分:1)

你不需要hibernate-annotation.jar,因为它包含在hibernate 5中的hibernate-core中 只需删除hibernate注释jar并只保留hibernate-commons-annotation。