Category: hibernate
-
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 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 automatically update creation and update timestamp through hibernate?
Let’s say you have two columns in all of your tables , one to track when a record was created and another to track when it was last updated. You have chosen hibernate as your ORM framework and created corresponding entity classes as well. Hibernate allows you to update these columns automatically ! You just…
-
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…