Skip to main content


Showing posts with the label Spring Data JPA

Spring Data JPA with embedded database and Spring Boot

In this post, we will create a Restful web-services which will use JPA to persist the data in the embedded database(h2). Also, you can read more on Restful web-services . Adding pom.xml dependencies We will add spring-boot-starter-jpa to manage dependencies. We will use h2 embedded database server for persistence. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> Creating entities We have three entities in the example project viz. Product, Rating, User. @Entity @Table(name = "product_ratings", schema = "product") public class Rating { @Id @GeneratedValue @Column(name="rating_id") private Long ratingId; private double rating; @Column(name="product_