我使用JPA和Hibernate作爲它的實現。什麼maven2
依賴關係我需要在我的項目?如果我在Hibernate中使用JPA,我的項目應該具有哪些依賴關係?
3
A
回答
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>
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>