codeconsole opened a new issue, #14509:
URL: https://github.com/apache/grails-core/issues/14509

   When an application has multiple datasources or connections, things become 
problematic with autoTimestampEventListener because it is difficult to access 
the correct one.   For each datastore or connection, a new 
autoTimestampEventListener is registered.
   
   The 
[documentation](https://gorm.grails.org/latest/hibernate/manual/index.html#eventsAutoTimestamping)
 states:
   
   > . If you already have access to the datastore, you can execute the 
getAutoTimestampEventListener method. If you don’t have access to the 
datastore, inject the autoTimestampEventListener bean.
   
   You can't just inject the autoTimestampEventListener bean because there are 
multiple registered and having access to the datastore doesn't help if there 
are multiple connections (For instance a gorm mongo db with 2 connections will 
result in 2 autoTimestampEventListeners.
   
   For instance, the following will not work if `Car` and `Person` are in 
separate data sources or connections.
   
   ```groovy
   def car = new Car(name: 'Herbie')
   def person = new Person(name: 'Bob')
   autoTimestampEventListener.withoutTimestamps {
       car.save(flush: true)
       person.save(flush: true)
   }
   ```
   
   It would be nice if there was a mechanism to expose the correct 
`autoTimestampEventListener` for a given domain class.
   
   Perhaps even being able to do the following:
   
   ```groovy
   def car = new Car(name: 'Herbie')
   def person = new Person(name: 'Bob')
   Car.autoTimestampEventListener.withoutTimestamps {
       car.save(flush: true)
   }
   Person.autoTimestampEventListener.withoutTimestamps {
       person.save(flush: true)
   }
   ```
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to