Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20956

Grails discard domain object

void businessMethod(def object) {
    // invoke discard only on hibernate objects
    if (isDomainObject(object))
        object.discard()
    // other stuff
}

How could I verify if object is grails domain object and is managed by hibernate?

Upvotes: 0

Views: 801

Answers (2)

Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20956

    if (object.metaClass.respondsTo(object, "discard")) {
        object.discard()
    }

Upvotes: 1

dspies
dspies

Reputation: 1543

You could try

grailsApplication.domainClasses*.clazz.contains(Hibernate.getClass(object))

see:http://grails.1312388.n4.nabble.com/Check-if-object-is-a-domain-instance-td3224172.html

Upvotes: 1

Related Questions