2016-02-05 109 views
0

我正在运行一个grails项目。也许这个问题是针对初学者的,但仍然很重要。休眠操作异常

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

我使用: '乔达时间:乔达时间: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 

你能给我一个提示什么事吗?

+0

'date_created'在MySQL数据库中应用的列类型是什么? – yugo

+0

它是DATE类型 – Ectoras

回答

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

+1

第二个解决方案解决了我的问题。非常感谢你。你可以放弃我以前的评论。 :) – Ectoras