I am trying to persist an object which has one to many relation with other entity. Using CascadeType.ALL works but, indeed I do not want to delete that entity when I delete main object. Therefore I tried to use CascadeType.PERSIST. But when I use it it makes a select query and says that entity not found. So why hibernate does it when I use cascadeType.PERSIST.
Here is my class basically:
public class Employeer{
@Id
private String id;
@Column
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "employer_details", joinColumns = {@JoinColumn(name = "employeer_id", referencedColumnName = "id")}
, inverseJoinColumns = {@JoinColumn(name = "details_id", referencedColumnName = "id")})
private Set<Address> otherObjects= new HashSet<>();
}
So the question is why using CascadeType.PERSIST, does not persist Address element and creates a select query and says that entity not found. Why I want to use it, I do not want to delete entity from address table when I delete employeer.
Note: I was looking at this post. Unable find Entity .. while trying to save data . But there I am trying to get why CascadeType.PERSIST does not work.