我试图删除一个扩展“entry”的实体“study”。继承策略是
InheritanceType.JOINED
.
有一个研究表和一个条目表(带有公共字段)。
定义了两个存储库:
EntryRepository extends CrudRepository<Entry, String>
StudyRepository extends CrudRepository<Study, String>
这两个存储库扩展了spring数据
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
所以…日志中没有删除,没有错误…- -
你知道如何让它工作,或者如何找出这个问题的根源吗?
谢谢!