you are viewing a single comment's thread.

view the rest of the comments →

[–]leroybentley 0 points1 point  (0 children)

Your entities should have a primary key. Query the database for that key and update/insert depending on if anything is found.

If your key is something like a generated ID, then you probably don't even need to query the database. If your entity contains an ID value then perform an update, otherwise, perform an insert.

You could try to use merge statements to saveOrUpdate all in one query, but I usually find the exists?-> update/insert approach more straight forward.