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.6
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 thecascade
attribute.Valid settings for the cascade attribute include:
merge
- merges the state of a detached associationsave-update
- cascades only saves and updates to an associationdelete
- cascades only deletes to an associationlock
- useful if a pessimistic lock should be cascaded to its associationsrefresh
- cascades refreshes to an associationevict
- cascades evictions (equivalent todiscard()
in GORM) to associations if setall
- cascade all operations to associationsall-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 usageTo 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 }