In Hibernate 5.1.0 / JPA 2.1, is there any way to merge based on a unique key instead of based on a primary key?
I have the values for a unique key as input from an external system, but the input obviously does not contain my internal primary key.
I'd like to be able to call EntityManager#merge(entity)
and, if the primary key of entity
isn't null, have Hibernate / JPA use the primary key to merge, but, if the primary key is null, use the unique key to merge (i.e. if the primary is null, and if the unique key corresponds to a row in the database, the row will be updated, but if there is no row in the database corresponding to the unique key, then a new row will be inserted).