hibernate AnnotationConfiguration is deprecated… b

2019-09-16 16:55发布

问题:

Here is my code:

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

which gives :

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

fine... so I try to use org.hibernate.cfg.AnnotationConfiguration instead :

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

but that class is deprecated. The docs instruct me to use Configuration instead!

As a side note, the AnnotationConfiguration option fails also, resulting in :

Caused by: java.lang.IncompatibleClassChangeError: Implementing class

Here is my pom.xml :

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

Help please!!!

回答1:

Use org.hibernate.cfg.Configuration, as you first tried, but replace the entry in pom.xml with:

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


回答2:

It turned out I had two different versions of hibernate lying around in my classpath. Once I resolved this and just used 4.3.0.Final, everything was fine. Silly me!