User:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String name;
@OneToOne(mappedBy = "user")
private Address address;
//Getters and setters
}
Address:
@Entity
public class Address {
@Id
private Long id;
@Column
private String country;
@OneToOne
@JoinColumn(name = "id")
@MapsId
private User user;
//Getters and setters
}
Below is the error I am getting:
2020-05-02 02:33:42 - Uncaught Runtime Exception
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance
User and Address classes both share the same Primary key..
Could you please tell me what still I have to change in my above code? I have written above based on some example I found, I will be glad if someone could explain me whats happening internally
EDIT:
I am trying to insert User having RequestBody as below, then facing above exception.
{
"name": "john",
"adddress": {
"country": "US"
}
}