I have an object called invoice that has a field which is a complex object
public class Invoice {
@ManyToOne
@JoinColumn(name = "id_site_to")
private Site siteTo;
}
public class Site {
@Id
@GeneratedValue
@Column(name = "id_site")
private long id;
private String description;
...
}
in a point of my code, I create an Invoice from a DTO. The so-created invoice contains a Site without all fields populated but only the ID. When I try to save this invoice instance (with JPA repository), I get
org.hibernate.TransientPropertyValueException: Not-null property references a transient value
even if the site Id exists in the database. There's a way to perform this save without having to first get the site from the database with a select?