Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在hibernate的许多映射中,On delete CASCADE不起作用_Java_Hibernate_Hibernate Mapping - Fatal编程技术网

Java 在hibernate的许多映射中,On delete CASCADE不起作用

Java 在hibernate的许多映射中,On delete CASCADE不起作用,java,hibernate,hibernate-mapping,Java,Hibernate,Hibernate Mapping,我在hibernate和join表中有多对多映射,并且有3个不同的类OperationEntity和EndPointEntity具有许多映射。我尝试过使用@Cascade(org.hibernate.annotations.CascadeType.ALL)和@ManyToOne(Cascade=CascadeType.ALL)注释。但当签入数据库时,对删除和更新都有限制。代码如下: OperationEntity.java import java.io.Serializable; import

我在hibernate和join表中有多对多映射,并且有3个不同的类
OperationEntity
EndPointEntity
具有许多映射。我尝试过使用
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@ManyToOne(Cascade=CascadeType.ALL)
注释。但当签入数据库时,对删除和更新都有限制。代码如下:

OperationEntity.java

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="t_operation", schema="test")
public class OperationEntity implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="op_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int opId;

    @Column(name="op_name")
    private String opName;

    @Column(name="op_desc")
    private String opDesc;

    @OneToMany(mappedBy="operationsEntity")
    private List<OpEndPointEntity> listOfOperationsEndpoints;   

    public int getOpId() {
        return opId;
    }

    public void setOpId(int opId) {
        this.opId = opId;
    }

    public String getOpName() {
        return opName;
    }

    public void setOpName(String opName) {
        this.opName = opName;
    }

    public String getOpDesc() {
        return opDesc;
    }

    public void setOpDesc(String opDesc) {
        this.opDesc = opDesc;
    }

    public List<OpEndPointEntity> getListOfOperationsEndpoints() {
        return listOfOperationsEndpoints;
    }

    public void setListOfOperationsEndpoints(
            List<OpEndPointEntity> listOfOperationsEndpoints) {
        this.listOfOperationsEndpoints = listOfOperationsEndpoints;
    }

}


    EndPointEntity.java

    import java.io.Serializable;
    import java.util.List;

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;

    @Entity
    @Table(name="t_endPoint", schema="test")
    public class EndPointEntity implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @Column(name="end_point_id")
        @GeneratedValue(strategy=GenerationType.AUTO)
        private int endPointId;

        @Column(name="end_point")
        private String endPoint;

        @Column(name="end_point_desc")
        private String endPointDesc;

        @OneToMany(mappedBy="endPointEntity")
        private List<OpEndPointEntity> listOpEndPoint;

        public int getEndPointId() {
            return endPointId;
        }

        public void setEndPointId(int endPointId) {
            this.endPointId = endPointId;
        }

        public String getEndPoint() {
            return endPoint;
        }

        public void setEndPoint(String endPoint) {
            this.endPoint = endPoint;
        }

        public String getEndPointDesc() {
            return endPointDesc;
        }

        public void setEndPointDesc(String endPointDesc) {
            this.endPointDesc = endPointDesc;
        }

        public List<OpEndPointEntity> getListOpEndPoint() {
            return listOpEndPoint;
        }

        public void setListOpEndPoint(List<OpEndPointEntity> listOpEndPoint) {
            this.listOpEndPoint = listOpEndPoint;
        }
    }


    Mapping class : OpEndPointEntity.java

    import java.io.Serializable;

    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;

    import org.hibernate.annotations.Cascade;

    @Entity
    @Table(name="t_op_endpoint_map", schema="test")
    public class OpEndPointEntity implements Serializable {
        private static final long serialVersionUID = 71L;

        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Column(name="OP_ENDPOINT_ID")
        private Integer operationEndpointId;

        @ManyToOne(cascade=CascadeType.ALL)
        @Cascade(org.hibernate.annotations.CascadeType.ALL)
        @JoinColumn(name="end_point_id")
        private EndPointEntity endPointEntity;

        @ManyToOne
        @Cascade(org.hibernate.annotations.CascadeType.ALL)
        @JoinColumn(name="op_id")
        private OperationEntity operationsEntity;

        public Integer getOperationEndpointId() {
            return operationEndpointId;
        }

        public void setOperationEndpointId(Integer operationEndpointId) {
            this.operationEndpointId = operationEndpointId;
        }

        public EndPointEntity getEndPointEntity() {
            return endPointEntity;
        }

        public void setEndPointEntity(EndPointEntity endPointEntity) {
            this.endPointEntity = endPointEntity;
        }

        public OperationEntity getOperationsEntity() {
            return operationsEntity;
        }

        public void setOperationsEntity(OperationEntity operationsEntity) {
            this.operationsEntity = operationsEntity;
        }

    }
import java.io.Serializable;
导入java.util.List;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.OneToMany;
导入javax.persistence.Table;
@实体
@表(name=“t_操作”,schema=“测试”)
公共类OperationEntity实现可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@列(name=“op_id”)
@GeneratedValue(策略=GenerationType.AUTO)
私人内部opId;
@列(name=“op_name”)
私有字符串名称;
@列(name=“op_desc”)
私有字符串opDesc;
@OneToMany(mappedBy=“operationsEntity”)
操作发送点的私有列表;
public int getOpId(){
返回opId;
}
公共无效setOpId(int opId){
this.opId=opId;
}
公共字符串getOpName(){
返回opName;
}
public void setOpName(字符串opName){
this.opName=opName;
}
公共字符串getOpDesc(){
返回opDesc;
}
公共void setOpDesc(字符串opDesc){
this.opDesc=opDesc;
}
公共列表GetListofOperationsSendpoints(){
返回操作发送点列表;
}
public void setListofOperationsSendpoints(
操作列表(发送点){
this.listofOperationsSendpoints=listofOperationsSendpoints;
}
}
EndPointEntity.java
导入java.io.Serializable;
导入java.util.List;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.OneToMany;
导入javax.persistence.Table;
@实体
@表(name=“t_端点”,schema=“测试”)
公共类EndPointEntity实现可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@列(name=“end\u point\u id”)
@GeneratedValue(策略=GenerationType.AUTO)
私有int-endPointId;
@列(名称=“结束点”)
私有字符串端点;
@列(name=“end\u point\u desc”)
私有字符串endPointDesc;
@OneToMany(mappedBy=“endPointEntity”)
私有列表列表opendpoint;
public int getEndPointId(){
返回endPointId;
}
public void setEndPointId(int endPointId){
this.endPointId=endPointId;
}
公共字符串getEndPoint(){
返回端点;
}
公共void setEndPoint(字符串端点){
this.endPoint=端点;
}
公共字符串getEndPointDesc(){
返回endPointDesc;
}
公共void setEndPointDesc(字符串endPointDesc){
this.endPointDesc=endPointDesc;
}
公共列表getListOpEndPoint(){
返回列表opendpoint;
}
public void setListOpEndPoint(列表listOpEndPoint){
this.listOpEndPoint=listOpEndPoint;
}
}
映射类:OpEndPointEntity.java
导入java.io.Serializable;
导入javax.persistence.CascadeType;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.JoinColumn;
导入javax.persistence.manytone;
导入javax.persistence.Table;
导入org.hibernate.annotations.Cascade;
@实体
@表(name=“t\u op\u endpoint\u map”,schema=“test”)
公共类OpEndPointEntity实现可序列化{
私有静态最终长serialVersionUID=71L;
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“OP\u ENDPOINT\u ID”)
私有整数运算符ndpointId;
@多通(级联=级联类型.ALL)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name=“end\u point\u id”)
私有端点实体端点实体;
@许多酮
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name=“op_id”)
私人经营实体经营实体;
公共整数getOperationEndpointId(){
返回操作ndpointid;
}
public void setOperationEndpointId(整型operationEndpointId){
this.operationEndpointId=operationEndpointId;
}
公共端点实体getEndPointEntity(){
返回端点实体;
}
公共void setEndPointEntity(EndPointEntity EndPointEntity){
this.endPointEntity=endPointEntity;
}
公共操作实体getOperationsEntity(){
退货经营主体;
}
公共无效集合operationsEntity(OperationEntity operationsEntity){
this.operationsEntity=operationsEntity;
}
}

请提供在删除和更新时进行级联的方法。这可能是jar问题吗?

您是从Java代码中删除它还是使用终端?如果您从终端删除它,它将无法工作。使用mysqldump进行备份后,您将看到该sql文件中没有ON DELETE SET NULL或ON DELETE CASCADE。这意味着它只适用于Java代码。尝试从Java代码中删除它。我不知道你是怎么删除的。我需要查看这两个类才能查看代码。

您是否从Java c中删除了它