Category: Spring Data
-
How to query data in Spring Data through Example?
One of the frequent operations you perform on a database is retrieving data based on certain criteria. Let’s say you have a table containing developer details , their name , experience and their primary technology skill. And you want your app to be able to query this data. There are many ways to do this.…
-
What is @MapsId used for in JPA/Hibernate? – Part II
In the previous post , we saw how and why to use @MapsId in a One to One relationship. In this post , lets see how it comes handy in a One to Many relationship. Let’s take the same Musician entity as the parent object. Let’s take an Album entity as the child object. A…
-
What is @MapsId used for in JPA/hibernate? – Part 1
@MapsId annotation. If you ever wondered what this annotation is for , here is an in depth analysis of it: When is this annotation used? It is used if the primary key of a child table is the same as the primary key of a parent table Why is this used? By specifying the annotation…
-
How to group related attributes together while doing hibernate entity mapping?
Let’s say you have chosen Hibernate ORM to save data to your database. For each table you have written a corresponding entity class in your java application. And then while doing so you start noticing that a lot of the entity classes have few fields repeated. You wonder if it would be nice to keep…
-
What are the different ways to delete a child entity in JPA/hibernate through Spring Data?
Let’s say you have an application which creates blog posts and saves them and also the comments user enter on the posts. The Blogpost and the comment represent a parent and child relationship. You may want to delete the comments in three different ways: Delete the comment whenever the blogpost is deleted. Delete the comment…
-
How to save both parent and child records on saving parent record in JPA/hibernate?
Let’s say you have created an application to post blogs. You are allowing users to comment on the blogs. Every blog is associated with many comments. You have chosen spring data as your backend technology. How would you design this ? You can create an entity class representing a blog post , say Blogpost.java And…
-
How to map JSON data in PostGreSQL database to a Hibernate Entity column?
PostGreSQL database is one of the most popular open source databases . It has features which traditional relational databases lack , like storing a JSON as itself in the database. JSON is a widely used communication data format and hence this feature comes quite handy. The problem arises when you use an ORM tool like…
-
How to handle pagination and sorting in Spring Data?
Let’s say you want to handle pagination and sorting for your application and you don’t want to do the hard work of writing SQL queries or setting criteria using an ORM tool. Spring Data provides a very simple and efficient way to handle pagination and sorting. All you have to do is create a repository…
-
How to generate REST services automatically for data repositories using Spring Boot?
There is no need to write REST service controller classes yourself if you just want to expose your databases as REST services. Spring Boot can automatically convert your database repositories into REST services. In addition to it, it returns the response in HAL format which allows you to navigate to the individual records. Let’s see…
-
How to integrate SQLite Database with Spring Boot?
Spring Boot doesn’t provide a straightforward way to integrate SQLite database compared to other databases such as MySQL , MongoDB etc. SQLite is the most used database engine in the world as SQLite website claims. And yet it is a surprise Spring Boot doesn’t treat it the same way as it treats other databases. To…