1

人们使用什么技术来有效地防止对大量类进行级联删除?

我有以下域类:但是当我删除一个类别项目时,它也会删除所有与类别相关的 genericProduct 项目。现在我该如何防止这种情况

class Category {

String name
static hasMany      =  [manufacturers: Manufacturer, genericProducts:GenericProduct]
static mappedBy     =  [genericProducts:'categories']
AuditUser audit     =  new AuditUser()
static embedded     =  ['audit']    
static constraints  =  {
    name  blank: false, size: 0..60, unique: false
}
static mapping = {
    table 't01i001'
    id      column: 'f_category_id'
    name    column: 'f_name',       length: 60     
    version column: 'f_revision'

    manufacturers joinTable: [name: 't01j001', key: 'k_category_id', column: 'k_manufacturer_id']
}

class GenericProduct {

String name

static belongsTo  =  [categories:Category]
static hasMany    =  [brands:Brand]
static mappedBy   =  [brands:'genericProducts']

AuditUser audit = new AuditUser()
static embedded = ['audit']  

static constraints = {
    name     blank: false, size: 0..60, unique: false
}

static mapping = {
    table 't01i003'
    id          column: 'f_generic_product_id'
    name        column: 'f_name', length: 30  
    categories  column: 'f_cat_id', length: 30  
    version     column: 'f_revision'
}
4

1 回答 1

2

下次我添加一些配置以防止级联删除然后它可以工作

class Category {

    String name
    static hasMany      =  [manufacturers: Manufacturer, genericProducts:GenericProduct]
    static mappedBy     =  [genericProducts:'categories']
    AuditUser audit     =  new AuditUser()
    static embedded     =  ['audit']    
    static constraints  =  {
        name  blank: false, size: 0..60, unique: false
    }
    static mapping = {
        manufacturers   cascade: 'save-update'
        genericProducts cascade: 'save-update'

        table 't01i001'
        id      column: 'f_category_id'
        name    column: 'f_name',       length: 60     
        version column: 'f_revision'

        manufacturers joinTable: [name: 't01j001', key: 'k_category_id', column: 'k_manufacturer_id']
    }
于 2013-04-01T05:15:45.577 回答