
spring+hibernate+mysql 只能使用mysql的innodb设置外键进行级联删除吗? 5
2个回答
展开全部
CREATE TABLE SC(
Sno CHAR(8) ,
foregin key (Sno) references Student(Sno)
);
友情提示一下楼主,MySQL的外键只能在InnoDB表中使用。这个很关键,因为一般都会使用默认的MyISAM。
Sno CHAR(8) ,
foregin key (Sno) references Student(Sno)
);
友情提示一下楼主,MySQL的外键只能在InnoDB表中使用。这个很关键,因为一般都会使用默认的MyISAM。
展开全部
package entity;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Cacheable;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Cacheable
@Table(name="DEPARTMENTS")
@Entity
public class Department {
private Integer id;
private String departmentName;
private String introduction;
private Set<Employee> employees = new HashSet<Employee>();
@GeneratedValue
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
// 与private Department department;的getter方法上的 @JoinColumn(name="DEPARTMENT_ID") 一致
@Cascade(CascadeType.DELETE)
@JoinColumn(name="DEPARTMENT_ID")
@OneToMany(fetch=FetchType.LAZY)
public Set<Employee> getEmployees() {
return employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
}
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Cacheable;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Cacheable
@Table(name="DEPARTMENTS")
@Entity
public class Department {
private Integer id;
private String departmentName;
private String introduction;
private Set<Employee> employees = new HashSet<Employee>();
@GeneratedValue
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
// 与private Department department;的getter方法上的 @JoinColumn(name="DEPARTMENT_ID") 一致
@Cascade(CascadeType.DELETE)
@JoinColumn(name="DEPARTMENT_ID")
@OneToMany(fetch=FetchType.LAZY)
public Set<Employee> getEmployees() {
return employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询