English 中文(简体)
在铁路公司,在洛德(Load)(a)等域类中是否有东西?
原标题:In Grails is there something in domain class like onLoad()?

Guys

我有以下领域:

class Product { 
    String name, 
    String productRecord,

    static transients = [ productRecord ]
}

产品记录是一个根据产品例的补贴自动产生的领域。

因此,我想到的是,如果一个领域的例子要求产生产品注册号,是否将自动被称作一个地方?

这样做的最佳方式是什么?

最佳回答

http://gorm.grails.org/latest/hibernate/manual/#eventsAutotimestamping”rel=“nofollow noreferer”>built-in territorial Activities:

GORM supports the registration of events as methods that get fired when certain events occurs such as deletes, inserts and updates. The following is a list of supported events:

  • beforeInsert - Executed before an object is initially persisted to the database
  • beforeUpdate - Executed before an object is updated
  • beforeDelete - Executed before an object is deleted
  • beforeValidate - Executed before an object is validated
  • afterInsert - Executed after an object is persisted to the database
  • afterUpdate - Executed after an object has been updated
  • afterDelete - Executed after an object has been deleted
  • onLoad - Executed when an object is loaded from the database

查阅一些例子。

问题回答

通常的做法是,采用一种只读取的方法,并在其中采用代相传的逻辑。 例如:

class Product { 
    String name, 
    String getProductRecord{ "Record " + id },

    static transients = [ productRecord ]
}

另一个例子是here





相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签