我正在寻找一个适用于Grails(GORM)实例的"isDeleted()"测试:
在我的应用中,可能删除 p 标签的逻辑在其他地方,传递标志返回或其他操作会很繁琐。
Project p = ... get persistent entity from somewhere ...
p.delete() // done in some nested logic
... sometime later in the code prior to commit of the tx ...
if (!p.isDeleted()) ... do some more stuff ...
在我的应用中,可能删除 p 标签的逻辑在其他地方,传递标志返回或其他操作会很繁琐。
org.hibernate.impl.SessionImpl
实现的是org.hibernate.engine.SessionImplementor
接口。 - Burt Beckwithboolean deleted = Project.withSession { session -> session.persistenceContext.getEntry(p)?.status in [null, Status.DELETED] }
,因为该实体对于我来说不在会话中 - 可能是因为它已经使用 flush: true 删除了。 - Chris Peacock