Cascade.all没有使用spring boot和jparepository

时间:2018-04-16 18:05:35

标签: java spring jpa

我正在使用Jsprepository,我无法使用cascade.all

删除行
  

错误=内部服务器错误,message =无法执行语句; SQL [不适用];约束[null];嵌套异常是org.hibernate.exception.ConstraintViolationException:无法执行语句

Parameter.java

@Entity
@Data
@Table(name = "parameter")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Parameter {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @Column(name = "num")
    private Integer number;

    @Size(max = 255)
    @Column(name = "text")
    private String text;

    @Column(name = "bool")
    private Boolean bool;

    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;

}

Group.java

@Entity
@Data
@Table(name = "group_")
@NoArgsConstructor
public class Group {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Size(max = 255)
    @Column(name = "code")
    private String code;

    @Size(max = 255)
    @Column(name = "name")
    private String name;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "parameter_id")
    private Parameter parameter;
}

GroupService.java

@Service
public class GroupService {

    @Autowired
    private GroupRepository groupRepository;


    public void deleteGroup(Long id){
        groupRepository.deleteById(id);
    }

}

0 个答案:

没有答案