LocalVariableDeclarationStatement - The method addAnnotatedClass() is undefined for the type Configuration

不羁岁月 提交于 2019-12-12 03:39:07

问题


My pom.xml is :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>HibernateOneToOneMapping</groupId>
    <artifactId>HibernateOneToOneMapping</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.0.2.Final</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>


        <!-- http://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-annotations -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.4.Final</version>
        </dependency>
    </dependencies>
</project>

For create a Session Factory object :

SessionFactory factory = new Configuration().configure().addAnnotatedClass(com.bean.Stock.class)            .addAnnotatedClass(com.bean.StockDetail.class).buildSessionFactory();

Problem :

Can not resolve the method name addAnnotatedClass from org.hibernate.cfg.configuration class.


回答1:


Use following maven dependency :

<!-- http://mvnrepository.com/artifact/antlr/antlr --> <!-- http://mvnrepository.com/artifact/dom4j/dom4j --> <!-- http://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-jta_1.1_spec --> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <!-- http://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations --> <!-- http://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api --> <!-- http://mvnrepository.com/artifact/org.jboss/jandex --> <!-- http://mvnrepository.com/artifact/org.javassist/javassist --> <!-- http://mvnrepository.com/artifact/org.jboss.logging/jboss-logging --> <!-- http://mvnrepository.com/artifact/mysql/mysql-connector-java -->



来源:https://stackoverflow.com/questions/37802654/localvariabledeclarationstatement-the-method-addannotatedclass-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!