|
Hi All,
Each time I touch GORM, each time I get mad. Maybe this is a silly thing that I'm missing but otherwise it is a big bug. Let's go: output after => // Insert a quote def quote = new Quote(lastUpdated:Calendar.getInstance().getTime()).save(flush:true) // Insert a second quote but changing the date to 2007 Calendar pastDate = Calendar.getInstance(); pastDate.set(2007,0,1); println "Past date before: ${pastDate.getTime()}" => Past date before: Mon Jan 01 14:14:41 CET 2007 def quote2 = new Quote(lastUpdated:pastDate.getTime()).save(flush:true) => Hibernate: insert into quotes (..., lastUpdated) values (..., ?) // Cool, now let's get the quotes and print the dates to be sure def quotes = Quote.findAll() quotes.each() { println "Date quote 1 findAll: ${it.id} - ${it.lastUpdated}" } =>Date quote 1 findAll: 3 - Sat Apr 19 14:14:41 CEST 2008 =>Date quote 1 findAll: 4 - Sat Apr 19 14:14:41 CEST 2008 WTF? Where is my 2007? Now, it could be my DB. By running describe in MySQL says lastUpdated DATETIME NULL. So, nullable, and no default. So either I must be making a biiig mistake which wouldn't be rare or this is a bug. Best Regards, Martin |
|
Look at http://docs.codehaus.org/display/GRAILS/GORM+-+Events , last paragraph about automatic timestamping.
GORM handles lastUpdated for you, so either switch that behaviour off or use a different name for the property. Michael Am 19.04.2008 um 07:26 schrieb Martin Perez: Hi All, |
|
Damm!
Two hours of pain just for choosing the wrong variable name :'( Thanks a million, Michael. Changing the name of the variable fixed both the bug and my headache. Regards, Martin P.S. In this case I cannot use the lastUpdated feature provided by grails, because my lastUpdated should only change when a concrete attribute changes and not other attributes of the entity. It would probably be good to make more visible this kind of things like "you cannot use this variable as attribute" On Sat, Apr 19, 2008 at 3:04 PM, Michael Baehr <[hidden email]> wrote:
|
| Powered by Nabble | Edit this page |
