java - 删除具有继承的实体不适用于弹簧数据
问题描述
我正在尝试删除扩展“条目”的实体“研究”。继承策略是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
所以......日志中没有删除,没有错误,...... :-/关于如何让它工作或如何得到这个问题的根源的任何想法?
谢谢!
解决方案
推荐阅读
- python - 为什么 x 坐标是时间戳列表,鼠标移动(悬停)时不显示为 matplotlib 中的坐标?
- javascript - JavaScript打印数组结果在同一个文件中
- java - Google People API - 如何删除联系人的文字生日?
- java - JaxbAnnotationIntrospector ClassNotFound 在第一次调用
- reactjs - 创建逻辑以将数据传递到反应导航上的前一个屏幕时,TS lint 触发错误
- python - 如何用python根据主题对英语单词进行分类?
- multithreading - C++11:是否有任何用户相关的线程 ID?
- php - 使用php的小时和分钟总和之间的差异
- android-studio - 从 Url 下载 .apk 并安装 apk
- magento2 - 有谁知道为什么 product_id 不再保存在 sales_order_item 表中?