Quantcast

dateCreated, lastUpdated in Grails 2.0

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

dateCreated, lastUpdated in Grails 2.0

Srdan Dukic
Hi,

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic 'dateCreated' and 'lastUpdated' fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error 2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error 2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away. Have the 'dateCreated' and 'lastUpdated' fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Sorry if this question has been asked before, I've been trying to search for an answer to this but can't seem to find it.

Thank you
--
Srđan Đukić
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: dateCreated, lastUpdated in Grails 2.0

Andréas Kühne
Hi,

I also have dateCreated and lastUpdated fields in my domain classes (migrated without data from 1.3.7) and it works perfectly. Do you have any items in the database that violate the constraints? (ie with null value in the date_created field?)

Regards,

Andréas

2012/1/29 Srdan Dukic <[hidden email]>
Hi,

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic 'dateCreated' and 'lastUpdated' fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error 2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error 2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away. Have the 'dateCreated' and 'lastUpdated' fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Sorry if this question has been asked before, I've been trying to search for an answer to this but can't seem to find it.

Thank you
--
Srđan Đukić


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: dateCreated, lastUpdated in Grails 2.0

Srdan Dukic
Hi,

I'm using the development environment with "dbCreate" set to "create-drop" and the database I'm using is Postgres 8.4. 

Because it's "create-drop" I'm creating the domain classes in my BootStrap file and not specifying either the dateCreated or lastUpdated when creating the new objects. Neither of the fields are mentioned in the constraints at all i.e. "nullable" set to the default. 

Previously, Grails/GORM automatically populated and updated these fields when I created/edited the objects without me having to specify these fields when calling "new".

Do I now have to explicitly include them when creating new objects e.g.:

def Task = new Task(name: "Foo", description: "Bar", dateCreated: DateTime.Now(), lastUpdated: DateTime.Now()).save()

I hope that this isn't the case as I quite liked the fact that all I had to do was declare the two fields in the Domain Class definition and the fields would be updated automatically.

Thank you
-- 
Srđan Đukić

On 30 January 2012 03:46, Andréas Kühne <[hidden email]> wrote:
Hi,

I also have dateCreated and lastUpdated fields in my domain classes (migrated without data from 1.3.7) and it works perfectly. Do you have any items in the database that violate the constraints? (ie with null value in the date_created field?)

Regards,

Andréas


2012/1/29 Srdan Dukic <[hidden email]>
Hi,

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic 'dateCreated' and 'lastUpdated' fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away. Have the 'dateCreated' and 'lastUpdated' fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Sorry if this question has been asked before, I've been trying to search for an answer to this but can't seem to find it.

Thank you
--
Srđan Đukić
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: dateCreated, lastUpdated in Grails 2.0

Ford Guo
I have the same problem in Grails 2.0.

-Ford

On Jan 30, 2012, at 7:50 AM, Srdan Dukic wrote:

Hi,

I'm using the development environment with "dbCreate" set to "create-drop" and the database I'm using is Postgres 8.4. 

Because it's "create-drop" I'm creating the domain classes in my BootStrap file and not specifying either the dateCreated or lastUpdated when creating the new objects. Neither of the fields are mentioned in the constraints at all i.e. "nullable" set to the default. 

Previously, Grails/GORM automatically populated and updated these fields when I created/edited the objects without me having to specify these fields when calling "new".

Do I now have to explicitly include them when creating new objects e.g.:

def Task = new Task(name: "Foo", description: "Bar", dateCreated: DateTime.Now(), lastUpdated: DateTime.Now()).save()

I hope that this isn't the case as I quite liked the fact that all I had to do was declare the two fields in the Domain Class definition and the fields would be updated automatically.

Thank you
-- 
Srđan Đukić

On 30 January 2012 03:46, Andréas Kühne <[hidden email]> wrote:
Hi,

I also have dateCreated and lastUpdated fields in my domain classes (migrated without data from 1.3.7) and it works perfectly. Do you have any items in the database that violate the constraints? (ie with null value in the date_created field?)

Regards,

Andréas


2012/1/29 Srdan Dukic <[hidden email]>
Hi,

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic 'dateCreated' and 'lastUpdated' fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away. Have the 'dateCreated' and 'lastUpdated' fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Sorry if this question has been asked before, I've been trying to search for an answer to this but can't seem to find it.

Thank you
--
Srđan Đukić

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: dateCreated, lastUpdated in Grails 2.0

Srdan Dukic
In reply to this post by Srdan Dukic
Hi,

I've, fixed it by manually setting the autoTimestamp variable to "true" in the domain class definitions:

    static mapping = {
    autoTimestamp true
    }

I would guess that this property is not set after migrating a project from Grails 1.3.7 to 2.0.0.

The documentation for the automatic timestamping properties can be found at: http://grails.org/doc/latest/guide/GORM.html#ormdsl

Cheers
-- 
Srđan Đukić

On 30 January 2012 12:50, Srdan Dukic <[hidden email]> wrote:
Hi,

I'm using the development environment with "dbCreate" set to "create-drop" and the database I'm using is Postgres 8.4. 

Because it's "create-drop" I'm creating the domain classes in my BootStrap file and not specifying either the dateCreated or lastUpdated when creating the new objects. Neither of the fields are mentioned in the constraints at all i.e. "nullable" set to the default. 

Previously, Grails/GORM automatically populated and updated these fields when I created/edited the objects without me having to specify these fields when calling "new".

Do I now have to explicitly include them when creating new objects e.g.:

def Task = new Task(name: "Foo", description: "Bar", dateCreated: DateTime.Now(), lastUpdated: DateTime.Now()).save()

I hope that this isn't the case as I quite liked the fact that all I had to do was declare the two fields in the Domain Class definition and the fields would be updated automatically.

Thank you
-- 
Srđan Đukić

On 30 January 2012 03:46, Andréas Kühne <[hidden email]> wrote:
Hi,

I also have dateCreated and lastUpdated fields in my domain classes (migrated without data from 1.3.7) and it works perfectly. Do you have any items in the database that violate the constraints? (ie with null value in the date_created field?)

Regards,

Andréas


2012/1/29 Srdan Dukic <[hidden email]>
Hi,

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic 'dateCreated' and 'lastUpdated' fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error <a href="tel:2012-01-29%2022" value="+12012012922" target="_blank">2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away. Have the 'dateCreated' and 'lastUpdated' fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Sorry if this question has been asked before, I've been trying to search for an answer to this but can't seem to find it.

Thank you
--
Srđan Đukić
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: dateCreated, lastUpdated in Grails 2.0

desperado2.inchd
This post has NOT been accepted by the mailing list yet.
In reply to this post by Srdan Dukic
For Grails 2.0 we have to add a mapping:

static mapping = {
       autoTimeStamp true
}

Grails 1.3.7 did it automatically but in 2.0 it has to be added manually.

Thank you,
Main Pal
Main Pal
Loading...