问题描述
我有一个使用Grails 1.3.7的应用程序,我刚刚迁移到了Grails 2.0。应用程序使用自动 dateCreated 和 lastUpdated 字段来管理与创建和修改对象相关的时间戳。升级后,出现以下错误:
|运行Grails应用程序
|错误2012-01-29 22:36:53,504 [线程-8]错误util.JDBCExceptionReporter - 错误:在date_created列中的空值违反非空约束
|错误2012-01-29 22:36:53,510 [线程8]错误events.PatchedDefaultFlushEventListener - 无法同步数据库状态与会话
在我的Domain Classes中注释掉上述字段会导致问题消失。
dateCreated 和 lastUpdated 字段已弃用Grails 2.0?如果是这样,这是否意味着我必须编写代码来手动处理此功能,或者是否已将代码移动到某种插件中,如
在类的定义中:
$ $ $ $ $ $ $ $ $ $ $ $ $
我猜这个属性在将项目从Grails 1.3.7迁移到2.0.0之后没有设置。
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?
Ok, 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.
这篇关于dateCreated,Grails 2.0中的lastUpdated字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!