Is there a JPA function for combining based on fields without Id?

The service that I create receives data from an external system that comes with the "external identifier" of the provider. When I save this data in our database, I also assign it an automatically generated identifier:

@Entity public class Content { @Id @GeneratedValue private Long id; private Long externalId; // many other fields } 

When an external system sends data for the same content (with the same external ID), it is deserialized into separate POJO content:

 Content c = deserialize(json); 

Is there something like EntityManager.merge that can load and update the corresponding row from the database using the externalId field rather than the id field?

+5
source share
1 answer

Almost, but if the external client does not know your identifier, you need to use the request to get the object (you really only need the object identifier). When you have an identifier, you can set it to a separate object and merge.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1263260/


All Articles