7.5.2.9 Custom Cascade Behaviour 3.1.1

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 7.5.2.9 Custom Cascade Behaviour - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 3.1.1 ## 7.5.2.9 Custom Cascade Behaviour As described in the section on cascading updates, the primary mechanism to control the way updates and deletes cascade from one association to another is the static belongsTo property. However, the ORM DSL gives you complete access to Hibernate's transitive persistence capabilities using the `cascade` attribute. Valid settings for the cascade attribute include: `merge` - merges the state of a detached association `save-update` - cascades only saves and updates to an association `delete` - cascades only deletes to an association `lock` - useful if a pessimistic lock should be cascaded to its associations `refresh` - cascades refreshes to an association `evict` - cascades evictions (equivalent to `discard()` in GORM) to associations if set `all` - cascade all operations to associations `all-delete-orphan` - Applies only to one-to-many associations and indicates that when a child is removed from an association then it should be automatically deleted. Children are also deleted when the parent is. It is advisable to read the section in the Hibernate documentation on transitive persistence to obtain a better understanding of the different cascade styles and recommendations for their usage To specify the cascade attribute simply define one or more (comma-separated) of the aforementioned settings as its value:

    class Person {    String firstName    static hasMany = [addresses: Address]    static mapping = {
            addresses cascade: "all-delete-orphan"
        }
    }
    class Address {
        String street
        String postCode
    }
| Quick Reference (hide)