嗨,我在映射我的实体时遇到了问题。我正在使用 JPA2 和 Hibernate 实现。我得到了带有@ManyToMany 注释的表格
http://img204.imageshack.us/img204/7558/przykladd.png
我将其映射为:
@Entity
@Table("employee")
class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private String name;
@ManyToMany
@JoinTable(name = "proj_emp",
joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"),
uniqueConstraints = @UniqueConstraint(columnNames = {"employee_id", "project_id"}))
private List<Project> projects; ...}
@Entity
@Table("project")
class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private String name;
@Column
private Integer budget;
@ManyToMany(mappedBy = "projects")
private List<Employee> employees; ...}
现在,当我从 Employee 中删除记录时,我想从表 proj_emp 中级联删除,但表 Project 中的任何内容都不能删除。
获得它的最佳方法是什么?
谢谢大卫