首页 > 解决方案 > 删除具有继承的实体不适用于弹簧数据

问题描述

我正在尝试删除扩展“条目”的实体“研究”。继承策略是InheritanceType.JOINED. 有一个学习表和一个条目表(带有公共字段)。

定义了两个存储库:

EntryRepository extends CrudRepository<Entry, String>
StudyRepository extends CrudRepository<Study, String>

这两个存储库扩展了 spring data org.springframework.data.repository.CrudRepository

问题是:这两个存储库的删除方法不起作用。没有错误,没有效果。对于其他实体(没有继承),它运行良好。

这是我的测试代码:

 System.out.println("entity exist?: " + entryRepository.existsById(entry.getId()));
 System.out.println("before delete parent: " + entryRepository.count());
 entryRepository.delete(entry);
 System.out.println("after delete parent: " + entryRepository.count());

 System.out.println("entity exist?: " + studyRepository.existsById(entry.getId()));
 System.out.println("before delete child1: " + studyRepository.count());
 studyRepository.delete((Study)entry);
 System.out.println("after delete child1: " + studyRepository.count());

日志结果:

Hibernate: select count(*) as col_0_0_ from entry entry0_ where entry0_."ID"=?
entity exist?: true
Hibernate: select count(*) as col_0_0_ from entry entry0_
before delete parent: 6
Hibernate: select count(*) as col_0_0_ from entry entry0_
after delete parent: 6

Hibernate: select count(*) as col_0_0_ from study study0_ inner join entry study0_1_ on study0_."ID"=study0_1_."ID" where study0_."ID"=?
entity exist?: true
Hibernate: select count(*) as col_0_0_ from study study0_ inner join entry study0_1_ on study0_."ID"=study0_1_."ID"
before delete child1: 3
Hibernate: select count(*) as col_0_0_ from study study0_ inner join entry study0_1_ on study0_."ID"=study0_1_."ID"
after delete child1: 3

所以......日志中没有删除,没有错误,...... :-/关于如何让它工作或如何得到这个问题的根源的任何想法?

谢谢!

标签: javaspringspring-bootspring-data-jpaspring-data

解决方案


推荐阅读