James
James

Reputation: 12806

Elegant way to handle upsert with Hibernate and MySQL

I'm currently working on a batch import feature that sits on top of Hibernate and MySQL. My goal is to have Upsert functionality for several tables. I'm finding myself writing a lot of code to deal with seeing if the row exists by key and branching to right method. I was wondering if there might be a better way, i.e. something analogous to the tools that come with SQL-Server SSIS but for Hibernate and MySQL. What tools or elegant solutions have you used to handle bulk Upserts with hibernate and/or MySQL?

Upvotes: 3

Views: 3247

Answers (1)

Andrew
Andrew

Reputation: 4624

You might look into MySQL's ON DUPLICATE KEY UPDATE feature:

https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

Upvotes: 5

Related Questions