class Person { ... def beforeDelete = { ... } }
def beforeDelete() { ActivityTrace.withNewSession { new ActivityTrace( eventName:"Person Deleted", data:name).save() } }
class Person { … static mapping = { autoTimestamp false } }
class Person { .. static mapping = { table 'people' } }
class Person { String firstName static mapping = { columns { firstName column:'First_Name', type:'text' } } }
class Person { Address address static mapping = { columns { address column:'Person_Adress_Id' } } }
class Person { static hasMany = [addresses:Address] static mapping = { columns { addresses column:'Person_Adress_Id' } } }
class Person { static hasMany = [addresses:Address] static mapping = { columns { addresses joinTable:[name:'Person_Addresses', key:'Person_Id', column:'Address_Id'] } } }
hibernate { cache.use_second_level_cache=true cache.use_query_cache=true cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider' }
static mapping = { //配置读写缓存 cache true //配置只读 cache usage:'read-only', include:'non-lazy' }
static mapping = { //缺省是“read-write”, //还可以是'read-only' 或 'transactional' addresses column:'Address', cache:true }
Person.findByFirstName("Fred", [cache:true]) def people = Person.withCriteria { like('firstName', 'Fr%') cache true }
class Person { … static mapping = { cache usage:'read-only', include:'non-lazy' } }
class Payment { //在根上进行指定 Integer amount static mapping = { tablePerHierarchy false } } class CreditCardPayment extends Payment { String cardNumber }
class Person { … static mapping = {//采用单独表记录主键产生值 id column:'person_id', generator:'hilo', params:[table:'hi_value' ,column:'next_value' ,max_lo:100] } }
class Person { String firstName String lastName static mapping = { id composite:['firstName', 'lastName'] } }
class Person { String firstName String address static mapping = { columns { firstName column:'First_Name', index:'Name_Idx' address column:'Address', index:'Name_Idx, Address_Index' } } }
class Person { static mapping = { version false } }
class Person { static hasMany = [addresses:Address] static mapping = { columns { addresses lazy:false } } }
class Person { String firstName static hasMany = [addresses:Address] static mapping = { addresses cascade:"all-delete-orphan" } }
static mapping = { //或sort 'name' sort name:"desc" }
Account.withTransaction { status -> …… if(dest.active) { dest.amount += amount } else { status.setRollbackOnly() } }
转载于:https://blog.51cto.com/bcptdtptp/303259