Redis(grails 插件)不持久化 Enum 对象

发布于 2024-11-26 15:41:02 字数 490 浏览 1 评论 0原文

我有一个 grails 域类,我必须在 Redis 中持久化,如下所示:

class A {
    String one
    Integer two

    B three

    E four

    mapWith = "redis"
}

class B {
    String name
}

enum E {
   VALUE1, VALUE2
}

当我使用 GORM .save() 方法持久化类 A 的实例时,Redis 会正确保存它,除了枚举字段“四”之外。

正如您所看到的,这一事实已被了解并报告如下: http://jira.grails.org/browse /GPREDIS-3

是否有一个好的解决方法来保存 Enum 或类似的东西? 我们正在考虑 String 对象数组,你觉得怎么样?

I've got a grails domain class I have to persist in Redis, something like this:

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".

As you can see the fact is known and reported here: http://jira.grails.org/browse/GPREDIS-3

Is there a good workaround to save Enum or something similar?
We're thinking about an array of String objects, what do you think?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2024-12-03 15:41:02

我已经基本实现了这个功能,但它不适用于 Gemfire,我正在等待所有受支持的 nosql 提供程序修复它,然后再推送修复。作为解决方法,您可以将 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"
}

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. 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, e.g.

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"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文