Jpa没有刷新删除

时间:2015-12-03 22:34:22

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

我有以下代码:

@Transactional
public class DbCrudServiceImpl implements DbCrudService {

    @Override
    public void cleanupDb() {
        ...
        serviceUserRepository.deleteAll(); //Spring data JPA repository for entity ServiceUser
        serviceUserRepository.flush();
        ...

    }

    ...
}

这是一个Spring bean。

我将Jpa属性中的hibernate.show_sql设置为true,将org.hibernate.event.internal.AbstractFlushingEventListener的记录器设置为DEBUG,以便检查cleanupDb中发生的情况。

显示的cleanupDb的行产生了log:

23:18:53.398 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:149 - ## Processing flush-time cascades
23:18:53.401 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:189 - ## Dirty checking collections
23:18:53.406 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:123 - ## Flushed: 0 insertions, 0 updates, 0 deletions to 8 objects
23:18:53.407 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:130 - ## Flushed: 0 (re)creations, 0 updates, 0 removals to 24 collections
Hibernate: select ... from SERVICE_USER ...
23:19:01.753 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:149 - ## Processing flush-time cascades
23:19:01.757 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:189 - ## Dirty checking collections
23:19:01.761 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:123 - ## Flushed: 0 insertions, 0 updates, 0 deletions to 8 objects
23:19:01.763 [main] DEBUG o.h.e.i.AbstractFlushingEventListener:130 - ## Flushed: 0 (re)creations, 0 updates, 0 removals to 24 collections

为什么没有删除声明? 为什么没有冲洗?

1 个答案:

答案 0 :(得分:1)

这可能是因为Hibernate遍历整个对象图,如果尚未删除父对象,则取消了子删除。

您可以通过将日志级别更改为TRACE来检查此问题,并从Hibernate中查找以下消息:

取消调度实体删除