Rest 使用Spring数据jpa删除记录

Rest 使用Spring数据jpa删除记录,rest,spring-boot,spring-data,Rest,Spring Boot,Spring Data,我有一个实体“能力”,该实体与其他两个实体有OneToMany关系:candidatecompetence和offreferecompetence,以及manytone与groupcompetency的关系 我有一个rest delete服务,它将采用能力实体的id,如下所示: @Secured("ROLE_ADMIN") @RequestMapping(value="/competences/{id}",method= RequestMethod.DELETE) public

我有一个实体“能力”,该实体与其他两个实体有
OneToMany
关系:
candidatecompetence
offreferecompetence
,以及
manytone
groupcompetency
的关系

我有一个rest delete服务,它将采用
能力
实体的id,如下所示:

@Secured("ROLE_ADMIN")
    @RequestMapping(value="/competences/{id}",method= RequestMethod.DELETE)
    public void deleteCompetence(@PathVariable Long id) {
        competenceMetier.deleteCompetence(id);
    }
public void deleteCompetence(Long id) {
        competenceRepository.delete(id);
    }
然后,
deleteCompetency
函数将从扩展
JpaRepository
的Competency存储库调用一个delete函数,如下所示:

@Secured("ROLE_ADMIN")
    @RequestMapping(value="/competences/{id}",method= RequestMethod.DELETE)
    public void deleteCompetence(@PathVariable Long id) {
        competenceMetier.deleteCompetence(id);
    }
public void deleteCompetence(Long id) {
        competenceRepository.delete(id);
    }
问题是,当我调用rest delete方法时,我得到200作为http响应,但正文中没有任何内容,对于日志也是一样,我在任何地方都看不到delete sql查询,并且实体仍然存在于数据库中

以下是我的实体:

能力: 候选资格: 团体能力:
@实体
公共类GroupCompetency实现了可序列化{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长期能力;
私有弦滴度;
私有布尔激活=真;
@OneToMany(mappedBy=“GroupCompetition”,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
私人收藏能力;
公共长GetCodeGroupCompetency(){
返回代码组能力;
}
公共无效SetCodeGroupCapability(长代码组权限){
this.codegroupCompetency=codegroupCompetency;
}
公共字符串getitre(){
回潮滴度;
}
公共无效设置标题(字符串标题){
这个。滴度=滴度;
}
公共团体能力(字符串标题){
这个。滴度=滴度;
}
公共团体能力(){
}
公共布尔getActivated(){
返回激活;
}
公共无效设置已激活(布尔值已激活){
这个.激活的=激活的;
}
公共收集能力(){
返回能力;
}
公共职能(收集职能){
这一点。能力=能力;
}
}

您应该用
@Transactional
注释您的服务方法
delete competitility

您应该使用
@Transactional
注释您的服务方法
delete competitility

@Entity
public class CandidatCompetence implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long codeCandidatCompetence;
    private String niveauExperience;
    @ManyToOne
    @JoinColumn(name = "candidat")
    private Candidat candidat;
    @ManyToOne
    @JoinColumn(name = "competence")
    private  Competence competence;

    public Long getCodeCandidatCompetence() {
        return codeCandidatCompetence;
    }
    public void setCodeCandidatCompetence(Long codeCandidatCompetence) {
        this.codeCandidatCompetence = codeCandidatCompetence;
    }
    public String getNiveauExperience() {
        return niveauExperience;
    }
    public void setNiveauExperience(String niveauExperience) {
        this.niveauExperience = niveauExperience;
    }
    public Candidat getCandidat() {
        return candidat;
    }
    public void setCandidat(Candidat candidat) {
        this.candidat = candidat;
    }
    public Competence getCompetence() {
        return competence;
    }
    public void setCompetence(Competence competence) {
        this.competence = competence;
    }
    public CandidatCompetence(String niveauExperience) {
        super();
        this.niveauExperience = niveauExperience;
    }
    public CandidatCompetence() {
        super();
        // TODO Auto-generated constructor stub
    }


}
@Entity
public class GroupCompetence implements Serializable {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long codeGroupCompetence;
    private String titre;
    private Boolean activated = true;

    @OneToMany(mappedBy="groupCompetence",cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<Competence> competences;

    public Long getCodeGroupCompetence() {
        return codeGroupCompetence;
    }

    public void setCodeGroupCompetence(Long codeGroupCompetence) {
        this.codeGroupCompetence = codeGroupCompetence;
    }

    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }

    public GroupCompetence(String titre) {
        this.titre = titre;
    }

    public GroupCompetence() {
    }

    public Boolean getActivated() {
        return activated;
    }

    public void setActivated(Boolean activated) {
        this.activated = activated;
    }

    public Collection<Competence> getCompetences() {
        return competences;
    }

    public void setCompetences(Collection<Competence> competences) {
        this.competences = competences;
    }
}