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?
Add the two dependencies below into the dependencies tag of the pom. xml .
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.
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.
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.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.2.Final</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With