Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - how to add all required dependencies for hibernate?

I have downloaded the zip from the Hibernate website and we have a folder which contains all required jars.

But I want to to this with Maven. Do I need to check which are the required libraries for this Hibernate version and add them manually in the pom.xml?

Is there a way just to add hibernate and maven to add all required libraries itself?

like image 729
Alexander Nikolov Avatar asked Nov 15 '15 13:11

Alexander Nikolov


People also ask

How many dependencies should be added in POM xml for adding Hibernate into your application?

Add the two dependencies below into the dependencies tag of the pom. xml .

What are the dependencies required to work with Hibernate?

System RequirementsHibernate 5.2 and later versions require at least Java 1.8 and JDBC 4.2. Hibernate 5.1 and older versions require at least Java 1.6 and JDBC 4.0. When building Hibernate 5.1 or older from sources, you need Java 1.7 due to a bug in the JDK 1.6 compiler.


3 Answers

If you want to use JPA with Hibernate, you only need a single Maven dependency. Refer to the download page:

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

This dependency will pull all the required other artifacts as transitive dependencies (like the JPA API, Hibernate Core and a lot of others).

This is the power of Maven. You don't need to add anything manually to the classpath or figure out yourself which jars you should add. One Maven dependency will declare as transitive dependencies everything that it needs.

like image 193
Tunaki Avatar answered Oct 17 '22 03:10

Tunaki


When specifying a dependency with pom.xml it won't be included into your dependencies library as you are expecting (a jar file). Here is a list of basic hibernate artifact ids that I use to include:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate.common</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>${hibernate.version}</version>
    <classifier>tests</classifier>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
</dependency>

Replace the ${hibernate.version} with desired version or define a property with this identifier.

like image 34
Abdelhak Avatar answered Oct 17 '22 04:10

Abdelhak


<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.0.2.Final</version>
</dependency>

Red arrow

like image 7
Poison Avatar answered Oct 17 '22 04:10

Poison