JPA (Hibernate) and postgres sql upsert using native query

I would like to perform a batch upgrade with JPA and Postgres. I cannot use merging, as I am checking the conflict on a unique Constraint that is not PK. I found that for updating in postgres we can now use ON Conflict functionality. So basically I would like to execute my own query execution in JPA . The request will look like this:

 INSERT INTO user (user_id, display_name ) VALUES('1', 'sg27') ON CONFLICT (user_id) DO UPDATE SET display_name = 'sg27' RETURNING *; 

I will loop over the list of objects and make a query.

So, my question is when the inline insert of the request, we can use manual cleaning, for example em.flush() . Will it work for batch insertion.

If not, then someone please tell me what are the possible solutions to this problem?

Thank you for your time.

+7
postgresql hibernate jpa upsert
source share

No one has answered this question yet.

See related questions:

636
What is the difference between JPA and Hibernate?
341
Create the perfect JPA object
28
How to enable batch inserts with Hibernate and Spring Boot
14
Postgres Conflict Handling with Several Unique Constraints
8
Conditional paste with Spring JPA / Hibernate
8
How to activate Postgres in a conflict on one of two columns?
7
How to simulate behavior using hibernate?
one
node.js and postgres bulk upsert or another template?
one
Is it possible to execute an upsert that requires filtering in Postgres?
0
Postgres: update row and update primary key column

All Articles