1
當我試圖救人時,它既不保存任何人也不保存任何城市。我不想保存或更新City對象。我只想更新/刪除joinColumn。有沒有辦法做到這一點?如何定義沒有級聯的單向OneToMany JPA關係?
Person person = new Person();
person.setCities(...);
personDAO.save(person);
public class Person{
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "city_id")
private List<City> cities;
}
public class City{
@Id
@Column(name = "city_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
private String cityId;
}
看到這個答案http://stackoverflow.com/questions/10551485/hibernate-cascade-type – Cherif
和我想再次考慮EagerFetch如果你的數據庫很大 – Cherif