简体   繁体   English

Redis(grails插件)不持久枚举对象

[英]Redis (grails plugin) does not persist Enum Object

I've got a grails domain class I have to persist in Redis, something like this: 我有一个grails域类,我必须在Redis中保留它,如下所示:

class A {
    String one
    Integer two

    B three

    E four

    mapWith = "redis"
}

class B {
    String name
}

enum E {
   VALUE1, VALUE2
}

When I persist an instance of class A with the GORM .save() method, Redis saves it correctly except for the enum field "four". 当我使用GORM .save()方法持久保存类A的实例时,Redis会正确保存它,枚举字段“ four”除外。

As you can see the fact is known and reported here: http://jira.grails.org/browse/GPREDIS-3 如您所见,事实是已知的,并在此处报告: http : //jira.grails.org/browse/GPREDIS-3

Is there a good workaround to save Enum or something similar? 有没有保存Enum或类似方法的好方法? We're thinking about an array of String objects, what do you think? 我们正在考虑一个String对象数组,您认为呢?

I've got this mostly implemented but it doesn't work for Gemfire and I'm waiting until it's fixed for all the supported nosql providers before pushing the fix. 我已经实现了大部分功能,但是它不适用于Gemfire,并且我一直等到针对所有受支持的nosql提供程序修复了该问题,然后再进行修复。 As a workaround you can use the inList constraint with a combination of a persistent String property and a non-persistent get/set pair with the name of your current property, eg 作为一种解决方法,可以将inList约束与持久性String属性和具有当前属性名称的非持久性get / set对结合使用,例如

class A {
   String one
   Integer two

   B three

   String fourString

   void setFour(E e) {
      fourString = e?.name()
   }
   E getFour() {
      fourString ? E.valueOf(fourString) : null
   }

   static constraints = {
      fourString inList: E.values()*.name()
   }

   static transients = ['fourString']

   static mapWith = "redis"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM