0

我的 pom.xml 是:

<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>

创建会话工厂对象:

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

问题 :

无法从 org.hibernate.cfg.configuration 类解析方法名称 addAnnotatedClass。

4

1 回答 1

0

使用以下 Maven 依赖项:

<!-- 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 -->

于 2016-06-15T03:08:22.180 回答