JPA-Maven Setup in IntelliJ
Technologies
- Maven
- Java 17
- JPA
- Hibernate
- PostgresSQL
How-to
- Open IntelliJ and create a new project.
- Select Maven and Java 17 or higher.
- In advanced settings, add groupId.
- Click finish.
- Open the pom.xml file and add the following dependencies:
<dependencies>
<!-- DB -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<!-- LOMBOK -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
<!-- TESTING -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
- Add the following lines into the properties tag
<hibernate-version>6.2.4.Final</hibernate-version>
<junit.version>5.9.1</junit.version>
- Create a new java class file called HibernateConfig.
8. Copy and paste the following Link into the HibernateConfig.class
If you get an import error, try to run Maven lifecycle “install”