Question: I have a grails job that is doing some processing on my data. This involves updating a title field after some string manipulations.

I am trying to have the lastUpdated stamp not affected by the above process, as users will often sort by lastUpdated. 

Is there a way to temporarily disable autoTimestamp ? I am using grails 2.4.5. 

I have tried this suggestion but did not work, and also vastly slows down processing (4sec was turned to 30sec)

```
def toggleAutoTimestamp(target, enabled) {
    def applicationContext = (ServletContextHolder.getServletContext()                                                           
                              .getAttribute(ApplicationAttributes.APPLICATION_CONTEXT))

    def closureInterceptor = applicationContext.getBean("eventTriggeringInterceptor")
    def datastore = closureInterceptor.datastores.values().iterator().next()
    def interceptor = datastore.getEventTriggeringInterceptor()

    def listener = interceptor.findEventListener(target)
    listener.shouldTimestamp = enabled
    null
}

```

\*\* Update \*\* 
Also I am not looking for solution involving the creation of a new field that only updates on specific scenarios (atm).

Answer: 
The class responsible for setting the timestamp according to the `autoTimestamp` mapping setting is [org.grails.orm.hibernate.support.ClosureEventListener](https://github.com/grails/grails-data-mapping/blob/8b0672e3e5047593037e556da111294acbcaf8af/grails-datastore-gorm-hibernate4/src/main/groovy/org/grails/orm/hibernate/support/ClosureEventListener.java).

I attempted to intercept the call to *handleTimestampingBeforeUpdate* using a Groovy Category and also with an Interceptor: neither worked. I suspect the *ClosureEventListener* is running in a different thread. I did not try with an *ExpandoMetaClass* because that would make a global change, affecting all attempts to `save()`.

Recommendation
==============

I think the best option for you is to:

1. Turn off the autoTimestamp in your mapping Closure.
2. Add a transient Boolean property to the domain class and use it as a flag to enable/disable updating the lastUpdated property.
3. Add the beforeUpdate Closure to your domain class and set (or not) the lastUpdated property manually according to the transient flag.
4. Modify the job to disable the flag prior to calling `save()`. An alternative is to implement a custom `save()` method that does this.

Important
---------

This approach requires turning off autoTimestamp because the *ClosureEventListener* sets the timestamp **after** `beforeUpdate()` gets called. So if autoTimestamp is not turned off changes to lastUpdated made in beforeUpdate() will be overwritten.
There is a flag called autoTimeflag

Example use:

```
static mapping = {
autoTimestamp false
}

```