坚持使用GORM的LocalDate列表 [英] Persist a list of LocalDate with GORM

查看:125
本文介绍了坚持使用GORM的LocalDate列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在grails中保留joda LocalDate的列表。我现在所拥有的是这样的:

I'm trying to persist a list of joda LocalDate in grails. What I have right now is something like this:

package com.publidirecta

import org.joda.time.LocalDate

class Evento {

    List <LocalDate> fechas = []

    static hasMany = [fechas:LocalDate]
}

,我得到以下错误:

and I get the following error :

MappingException: Missing type or column for column[fechas_persistent_local_date] on domain[Evento] referencing[org.jadira.usertype.dateandtime.joda.PersistentLocalDate]
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

我试过了hasMany属性,但它也不工作(只是没有添加任何东西)

I tried with out the hasMany property, but doesnt work either(just didnt add anything)

推荐答案

Alidad建议您将LocalDate换成新的实体,并与之建立一对多的关系这个实体。
此外,您必须注意将 LocalDate 类型映射到数据库,因为这不是Hibernate原生支持的类型。查看涵盖该主题的指南

As Alidad suggested you should wrap the LocalDate with a new entity and have a on-to-many relationship with this entity. In addition you will have to take care of mapping the LocalDate type to the database since this is not a type natively supported by Hibernate. Take a look at this guide which covers the topic.

使用用户类型库你的类应该看起来像这样:

Using the User Type library your class should look something like:

package com.publidirecta

class Evento {

    static hasMany = [fechas: Fecha]

    List <Fecha> fechas = []
}





And

import org.jadira.usertype.dateandtime.joda.PersistentLocalDate
import org.joda.time.LocalDate

class Fecha {
    LocalDate date

    static mapping = {
        date type: PersistentLocalDate
    }
}

确保将以下内容添加到 BuildConfig 中:

Make sure your add the following to your BuildConfig:

dependencies {
        compile 'org.jadira.usertype:usertype.jodatime:1.9'
    }

这篇关于坚持使用GORM的LocalDate列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆