【问题标题】:Creating insert operation using hibernate and I am getting the following error?使用休眠创建插入操作,我收到以下错误?
【发布时间】:2016-06-24 07:09:43
【问题描述】:

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

"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

【问题讨论】:

  • 请提供您的pom.xml 或库列表。
  • // '它只是一个包含映射文件和休眠配置文件的基本应用程序
  • 请验证所有实体类都在 xml 中正确配置。我怀疑某些实体类中缺少@entity 注释
  • 我试图创建任何基于实体的类。刚刚创建了 pojo 类
  • @KannanThangadurai 这是一个引导问题。

标签: java spring hibernate model-view-controller


【解决方案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 构建。

【讨论】:

  • 线程“主”org.hibernate.MappingException 中的异常:未知实体。我得到了这个异常
  • @BhRamya 看起来,您修复了一个错误。请将您的配置、创建会话工厂的代码、堆栈跟踪和 Hibernate 版本添加到您的问题中。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2014-12-23
    • 2016-02-03
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 2018-11-24
    相关资源
    最近更新 更多