void businessMethod(def object) {
// invoke discard only on hibernate objects
if (isDomainObject(object))
object.discard()
// other stuff
}
我如何验证对象是否是grails域对象并由hibernate管理?
答案 0 :(得分:1)
你可以尝试
grailsApplication.domainClasses*.clazz.contains(Hibernate.getClass(object))
见:http://grails.1312388.n4.nabble.com/Check-if-object-is-a-domain-instance-td3224172.html
答案 1 :(得分:1)
if (object.metaClass.respondsTo(object, "discard")) {
object.discard()
}