【问题标题】:hibernate AnnotationConfiguration is deprecated... but using Configuration results in MappingExceptionhibernate AnnotationConfiguration 已弃用...但使用 Configuration 会导致 MappingException
【发布时间】:2013-11-05 20:14:21
【问题描述】:

这是我的代码:

        Configuration config = new Configuration().configure();

给出:

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.google.musicstore.domain.Record"/>

很好...所以我尝试使用 org.hibernate.cfg.AnnotationConfiguration 代替:

        Configuration config = new AnnotationConfiguration().configure();

但该类已被弃用。文档指示我改用配置!

附带说明,AnnotationConfiguration 选项也失败,导致:

Caused by: java.lang.IncompatibleClassChangeError: Implementing class

这是我的 pom.xml:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>4.3.0.Final</version>
    </dependency>

请帮忙!!!

【问题讨论】:

    标签: hibernate configuration annotations


    【解决方案1】:

    使用org.hibernate.cfg.Configuration,就像您第一次尝试的那样,但将 pom.xml 中的条目替换为:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.3.Final</version>
    </dependency>
    

    【讨论】:

      【解决方案2】:

      原来我的类路径中有两个不同版本的hibernate。一旦我解决了这个问题并使用了 4.3.0.Final,一切都很好。傻我!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-14
        • 2017-09-18
        • 2015-11-10
        • 2022-12-21
        • 2020-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多