Hibernate操作异常

时间:2016-02-05 16:06:40

标签: hibernate grails jodatime

我正在运行一个grails项目。也许这个问题适合初学者,但仍然有帮助很重要。

我有一个域对象,订单。在订单类模型中,我使用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
你可以给我一个提示吗?

1 个答案:

答案 0 :(得分:0)

查看此solution

域类中的

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