下面是一個使用家長更新孩子的映射 - 爲他提供了很好的代碼來了解它的百路達
@Entity
@Table(name = "COMPANY")
@SequenceGenerator(name="CompanySeq", sequenceName="COMPANYseq", allocationSize=1)
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
/*
* Customer Company Details
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CompanySeq")
@Column(name = "COMPANY_ID")
private Integer id;
@Column(name="COMPANY_NAME")
private String name;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "COMPANY_ID",nullable=false)
@OrderBy(clause = "PRODUCT_NAME")
@ForeignKey(name = "fk_company_product")
private List<Product> products = new ArrayList<Product>();
}
@Entity
@Table(name = "PRODUCT")
@SequenceGenerator(name="CompanyProductSeq", sequenceName="COMPANY_PRODUCT", allocationSize=1)
public class Product implements Serializable{
/**
* SerialVersion ID
*/
private static final long serialVersionUID = 4073418246832063389L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CompanyProductSeq")
@Column(name = "PRODUCT_ID")
private Integer id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "COMPANY_ID", updatable = false, insertable = false, nullable=false)
private Company companyId;
@Column(name = "PRODUCT_NAME")
private String name;
}
你想要做什麼?從父級刪除子實體,還是刪除它們?這不是一回事。並告訴我們你的代碼,以瞭解你在做什麼。 –
您是否在使用列表或地圖將孩子與父母聯繫起來? – Logan
我正在使用List,但遺憾的是我無法在此處生成代碼,因爲它是禁止的。即使這個問題也被改寫了。 – seesee