Jpa 不刷新删除
Jpa not flushing delete
我有以下代码:
@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 行生成日志:
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
为什么没有删除语句?
为什么没有冲掉?
这可能是因为 Hibernate 遍历了整个对象图,如果父对象没有被删除,它就取消了子对象的删除。
您可以通过将日志级别更改为 TRACE 并从 Hibernate 中查找以下消息来检查这一点:
未安排实体删除
我有以下代码:
@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 行生成日志:
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
为什么没有删除语句? 为什么没有冲掉?
这可能是因为 Hibernate 遍历了整个对象图,如果父对象没有被删除,它就取消了子对象的删除。
您可以通过将日志级别更改为 TRACE 并从 Hibernate 中查找以下消息来检查这一点:
未安排实体删除