@Entity
@Table(name = "parent")
public final class Parent extends Base {
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
private Person person;
and doing (amongst other things) this :
Parent parent = new Parent();
Person person = new Person();
parent.setPerson(person);
session.save(parent);
I get the mentioned exception ?
Do I manually need to call session.save(person) before ? do I have to add a cascade type annotation to the childs class definition(where it references the parent) ?
Or have I missed something else obvious ?
I don't want to use CascadeType.ALL as when a parent is deleted I want to keep the person(child).
Both entities/tables extend a common Base table :
@MappedSuperclass()
public abstract class Base {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
public Integer getId() {
return id;
}
Will this effect which cascade type is required ?