cascade
目的 Purpose
Configures the cascading behavior of an association.使用例 Examples
class Author { static hasMany = [books: Book] static mapping = {
books cascade: 'all-delete-orphan'
}
}詳細 Description
Usage:
使用方法: association_name(cascade:string)Usage:
association_name(cascade:string)引数: Arguments:
cascade- The cascading behavior to define. Can be one or more (comma-separated) ofall,merge,save-update,delete,lock,refresh,evict,replicateorall-delete-orphan(one-to-many associations only).
class Book {
static belongsTo = [author: Author]
}class Author {
static hasMany = [books: Book]
}Author domain to the Book domain. So when an Author is deleted so will all the associated books.If the association doesn't define an owner (a "belongs to" relationship):class Book {
}class Author {
static hasMany = [books: Book]
}Author is deleted the Book associated domains won't be deleted. Use the cascade argument on an association to customize this behavior:class Author { static hasMany = [books: Book] static mapping = {
books cascade: 'all-delete-orphan'
}
}Book will also be deleted if it is removed (orphaned) from an Author's books association.See the section on transitive persistence in the Hibernate user guide.

