Hibernate运行异常

Hibernate operation exception

我是 运行 一个 grails 项目。也许这个问题是针对初学者的,但帮助仍然很重要。

我有一个领域对象,订单。在订单 class 模型中,我使用 Joda-Time 将 dateCreated 声明为 DateTime 类型。

我正在使用:'joda-time:joda-time:2.9.2'

然而,当调用 order.save() 时,出现以下错误:

Exception in thread "main" org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not execute statement; SQL [n/a]; Data truncation: Data too long for column 'date_created' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'date_created' at row 1

你能告诉我发生了什么事吗?

看看这个 solution:

在域中 Class:

import org.joda.time.*
import org.joda.time.contrib.hibernate.*

DateTime dateCreated
DateTime lastUpdated
LocalDate birthday

static mapping = {
    dateCreated type: PersistentDateTime
    lastUpdated type: PersistentDateTime
    birthday type: PersistentLocalDate
}

在Config.groovy中:

grails.gorm.default.mapping = {
    "user-type" type: PersistentDateTime, class: DateTime
    "user-type" type: PersistentLocalDate, class: LocalDate
}

another solution.