gs_vlad
gs_vlad

Reputation: 1449

Spring Data JPA detached entity back to context

I have Person entity with lazily fetched List<Contact> contacts.

I got my person entity object and some time later I want to get person's contacts (obviously I can do that only if entity is managed).

What is the best way to merge/put to context person entity in Spring Data JPA?

Upvotes: 1

Views: 296

Answers (1)

gs_vlad
gs_vlad

Reputation: 1449

This answers my question:

Person managedPerson = personRepository.save(person)

save method checks if person entity is new. If it is so, it persists entity, otherwise it merges it and returns back managed entity

Upvotes: 1

Related Questions