In Hibernate 5.1.0 / JPA 2.1, is there a way to merge based on a unique key, and not based on a primary key?
I have values ββfor a unique key as input from an external system, but the input does not explicitly contain my internal primary key.
I would like to be able to call EntityManager#merge(entity)
, and if the primary key of the entity
not null, use Hibernate / JPA to merge the primary key, but if the primary key is zero, use a unique key to merge (i.e. if the primary the object 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, a new row will be inserted).
source share