Hibernate Tips: How to remove entities from the persistence context before doing bulk operations
|

Hibernate Tips: How to remove entities from the persistence context before doing bulk operations

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please leave a comment below. Question: How do you remove entities from the persistence context before performing bulk update operations with JPQL or SQL?

What’s the difference between persist, save, merge and update? Which one should you use?
|

What’s the difference between persist, save, merge and update? Which one should you use?

JPA and Hibernate provide different methods to persist new and to update existing entities. You can choose between JPA’s persist and merge and Hibernate’s save and update methods. It seems like there are 2 pairs of 2 methods that do the same.  You can use the methods persist and save to store a new entity…

Hibernate Tips: How to model an association that doesn’t reference primary key columns
|

Hibernate Tips: How to model an association that doesn’t reference primary key columns

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please leave a comment below. Question: I have to map a legacy table model with Hibernate. It contains a many-to-one association that uses a non-primary…

JPA 2.2’s new getResultStream() method and how you should NOT use it
|

JPA 2.2’s new getResultStream() method and how you should NOT use it

JPA 2.2 introduced several new features, and one of them is the new getResultStream() method. This method is now part of the Query interface. As you might guess from its name, it allows you to retrieve the result of your query as a Stream. The goal of this method is to provide an efficient way to…