2016-02-05 111 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