what dependencies my project should have if I'm using JPA in Hibernate?

我的未来我决定 提交于 2019-12-05 02:36:31

问题


I use JPA, and Hibernate as its implementation. What maven2 dependencies I need to have in my project?


回答1:


I believe the only two things you need are hibernate's entitymanager and then one of the SLF4J logging bundles. Everything else should be pulled in as dependencies:

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



回答2:


Here's what I'm using. You may or may not want to keep the exclusion clauses; they make sense for me, since JTA and JPA are already included in the full Java EE APIs which I'm providing elsewhere. And if you're not using Commons Logging, you might want to pick a different slf4j implementation.

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


来源:https://stackoverflow.com/questions/3814761/what-dependencies-my-project-should-have-if-im-using-jpa-in-hibernate

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