不推荐使用hibernate AnnotationConfiguration ...但在MappingException中使用Configuration结果

时间:2013-10-26 20:11:02

标签: hibernate configuration annotations

这是我的代码:

        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();

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

作为旁注,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>

请帮助!!!

2 个答案:

答案 0 :(得分:1)

首次尝试使用org.hibernate.cfg.Configuration,但将pom.xml中的条目替换为:

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

答案 1 :(得分:0)

事实证明我在我的类路径中有两个不同版本的hibernate。一旦我解决了这个并且刚刚使用了4.3.0.Final,一切都很好。傻傻的我!