fanger8848 2017-05-20 11:08 采纳率: 25%
浏览 1075

hibernate级联删除报错,错误信息如下,求解答?

hibernate级联删除报错Cannot delete or update a parent row: a foreign key constraint fails (jk28.user_info_p, CONSTRAINT FK2BF43F36EB6FED6 FOREIGN KEY (MANAGER_ID) REFERENCES user_p (USER_ID))
这是哪里出现了问题了呢?求大神解答??

User实体类

public class User extends BaseEntity{
private String id;
private Dept dept;//用户与部门 多对一
private Userinfo userinfo ; //用户与用户扩展信息 一对一
//private Set roles = new HashSet(0);//用户与角色 多对多
private String userName;//用户名
private String password;//密码 要加密
private Integer state;//状态

public String getId() {
    return id;
}
public void setId(String id) {
    this.id = id;
}
public Dept getDept() {
    return dept;
}
public void setDept(Dept dept) {
    this.dept = dept;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public Integer getState() {
    return state;
}
public void setState(Integer state) {
    this.state = state;
}
public Userinfo getUserinfo() {
    return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
    this.userinfo = userinfo;
}

// public Set getRoles() {
// return roles;
// }
// public void setRoles(Set roles) {
// this.roles = roles;
// }
}

# Userinfo实体类
public class Userinfo extends BaseEntity {
private String id;
private String name;//姓名
private User manager;//用户与直属领导 多对一
private Date joinDate;//入职时间
private Double salary;//薪水
private Date birthday; //出生年月
private String gender; //性别
private String station;//岗位

private String telephone;//电话
private Integer degree;//等级
private String remark;// 备注
private Integer orderNo;//排序号
public String getId() {
    return id;
}
public void setId(String id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public User getManager() {
    return manager;
}
public void setManager(User manager) {
    this.manager = manager;
}
public Date getJoinDate() {
    return joinDate;
}
public void setJoinDate(Date joinDate) {
    this.joinDate = joinDate;
}
public Double getSalary() {
    return salary;
}
public void setSalary(Double salary) {
    this.salary = salary;
}
public Date getBirthday() {
    return birthday;
}
public void setBirthday(Date birthday) {
    this.birthday = birthday;
}
public String getGender() {
    return gender;
}
public void setGender(String gender) {
    this.gender = gender;
}
public String getStation() {
    return station;
}
public void setStation(String station) {
    this.station = station;
}
public String getTelephone() {
    return telephone;
}
public void setTelephone(String telephone) {
    this.telephone = telephone;
}
public Integer getDegree() {
    return degree;
}
public void setDegree(Integer degree) {
    this.degree = degree;
}
public String getRemark() {
    return remark;
}
public void setRemark(String remark) {
    this.remark = remark;
}
public Integer getOrderNo() {
    return orderNo;
}
public void setOrderNo(Integer orderNo) {
    this.orderNo = orderNo;
}

}

# User映射文件****
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">







  <property name="createBy" column="CREATE_BY"></property>
  <property name="createDept" column="CREATE_DEPT"></property>
  <property name="createTime" column="CREATE_TIME"></property>
  <property name="updateBy" column="UPDATE_BY"></property>
  <property name="updateTime" column="UPDATE_TIME"></property>


  <!-- private Dept dept;//用户与部门   多对一 -->
  <many-to-one name="dept" class="Dept" column="DEPT_ID"></many-to-one>

  <!--  private Userinfo userinfo ;  //用户与用户扩展信息    一对一 -->
  <one-to-one name="userinfo" class="Userinfo" cascade="all"></one-to-one>

  <!-- private Set<Role> roles = new HashSet<Role>(0);//用户与角色   多对多
  <set name="roles" table="ROLE_USER_P">
     <key column="USER_ID"></key>
     <many-to-many class="Role" column="ROLE_ID"></many-to-many>
  </set> -->


Userinfo映射文件******

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">





  <property name="name" column="NAME"></property>
  <property name="joinDate" column="JOIN_DATE"></property>
  <property name="salary" column="SALARY"></property>
  <property name="birthday" column="BIRTHDAY"></property>
  <property name="gender" column="GENDER"></property>
  <property name="station" column="STATION"></property>
  <property name="telephone" column="TELEPHONE"></property>
  <property name="degree" column="DEGREE"></property>
  <property name="remark" column="REMARK"></property>
  <property name="orderNo" column="ORDER_NO"></property>

  <property name="createBy" column="CREATE_BY"></property>
  <property name="createDept" column="CREATE_DEPT"></property>
  <property name="createTime" column="CREATE_TIME"></property>
  <property name="updateBy" column="UPDATE_BY"></property>
  <property name="updateTime" column="UPDATE_TIME"></property>

  <!--  private User manager;//用户与直属领导    多对一 
  <many-to-one name="manager" class="User" column="MANAGER_ID"></many-to-one>-->
</class>

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-20 15:53
    关注

    你删除的记录存在关联的数据,要关联的数据都删除了,才能删除它

    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式