删除具有继承关系的实体不适用于Spring数据

时间:2018-10-26 16:25:28

标签: java spring spring-boot spring-data-jpa spring-data

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

定义了两个存储库:

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

这两个存储库扩展了弹簧数据org.springframework.data.repository.CrudRepository

问题是:这两个存储库的delete方法不起作用。没有错误,没有影响。对于其他实体(没有继承),它很好用。

这是我的测试代码:

 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

所以...没有删除日志,没有错误,...:-/ 关于如何使它正常工作或如何获得此问题的根源有任何想法吗?

谢谢!

0 个答案:

没有答案