I'm trying to persist new entity Parent with the child that already exists in db. I don't want to update child during persistence of parent but just want to create a relationship. When I'm sending json from frontend it looks like this:
{ "child": { "id": 3 } }
On save I'm getting :
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
@Entity
class Parent {
@ManyToOne(optional = false)
@JoinColumn(name = "CHILD_ID", referencedColumnName = "CHILD_ID")
private Child child;
}
@Entity
class Child {
@Id
@Column(name="CHILD_ID")
private Long id;
}