Spring Boot with Thymeleaf tutorial, part 3 – Spring Data JPA

In this tutorial I am going to add a possibility of storing added posts in a database. I extend previous project where post form is already implemented. I use H2 in-memory database to simplify project’s complexity. To implement data access layer in the application I use Spring Data JPA.

1. Set up the project as is described in previous post or checkout the source code.

2. Add Maven dependencies to enable Spring Data JPA and H2 database:

Read more

Hibernate and PostgreSQL configuration using persistence.xml and EntityManager

In this tutorial I am going to show you how to use Hibernate with Entity Manager. It is based on my previous tutorial and it is an enhancement of this code. In previous tutorial I was using “hibernate-entitymanager” dependency, so there is no need to do any modifications in pom.xml now.

1. Create persistence.xml file in src/main/resources/META-INF directory. You can also remove hibernate.cfg.xml, but it is not mandatory.

Read more