如果我在Hibernate中使用JPA,我的项目应该具有哪些依赖项?

时间:2010-09-28 16:07:47

标签: java hibernate maven-2 jpa

我使用JPA,Hibernate作为其实现。我需要哪些maven2依赖项才能在我的项目中使用

2 个答案:

答案 0 :(得分:3)

我相信你需要的只有两件事是hibernate的entitymanager,然后是一个SLF4J日志包。其他所有内容都应该作为依赖项引入:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.5.1-Final</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <!-- version 1.5.8 is the latest version that will work with the slf4j-api 
            that's currently bundled with hibernate-parent -->
        <version>1.5.8</version>
    </dependency>

答案 1 :(得分:0)

这是我正在使用的。您可能会也可能不想遵守除外条款;它们对我有意义,因为JTA和JPA已经包含在我在其他地方提供的完整Java EE API中。如果你不使用Commons Logging,你可能想选择一个不同的slf4j实现。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.5.3-Final</version>
        <exclusions>
            <exclusion>
                <artifactId>jta</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.5.3-Final</version>
        <exclusions>
            <exclusion>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
                <groupId>org.hibernate.javax.persistence</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <!-- match version to the slf4j-api that's required by Hibernate -->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jcl</artifactId>
        <version>1.5.8</version>
    </dependency>