I have following entities:
@Entity @Table(name = "profile") public class Profile { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @OneToOne(cascade = CascadeType.ALL) private ProfileContacts profileContacts; ... } and
@Entity @Table(name = "profile_contacts") public class ProfileContacts { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "description") private String description; @Column(name = "first_name") private String firstName; @Column(name = "last_name") private String lastName; } I am trying to update it by sending this JSON with update to REST controller:
{ "id": 1, "description": "an update", "profileContacts": { "firstName": "John", "lastName": "Doe" } } so in the end it calls
profileRepository.save(profile); where profileRepository is instance of ProfileRepository class:
public interface ProfileRepository extends JpaRepository<Profile, Long> { } which is spring-data-jpa interface.
But each time after such update it updates profile table but adds new row to profile_contacts table (table which corresponds to ProfileContactsentity) instead of updating existing ones. How can I achieve updating?
profileobject content?