Grails:GORM 和 BitSets?

发布于 2024-08-10 21:38:47 字数 1501 浏览 6 评论 0原文

我在 官方文档 中没有看到任何有关不受支持的持久性数据类型的内容,因此我正在假设下工作应该处理 Groovy 语言中可用的类型。但是,对于以下域类:

class DocGroupPermissions {

   Workgroup workgroup
   Document document;
   BitSet permissions = new BitSet(2)

   void setPermissions(boolean canRead, boolean canWrite) {
       setReadPermissions(canRead)
       setWritePermissions(canWrite)
   }

   void setReadPermissions(boolean canRead) {
      permissions.set(0,canRead)
   }
   void setWritePermissions(boolean canWrite) {
      permissions.set(1,canWrite)
   }

   boolean getReadPermissions() {
      return permissions.get(0)
   }

   boolean getWritePermissions() {
      return permissions.get(1)
   }


   static belongsTo = [workgroup:Workgroup, document:Document]

   static constraints = {
      workgroup(nullable:false, blank:false)
      document(nullable:false, blank:false)
   }
}

我得到:

2009-11-15 16:46:12,298 [main] 错误 context.ContextLoader - 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名称为“messageSource”的bean时出错:bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“transactionManager”的bean时出错:设置bean属性“sessionFactory”时无法解析对bean“sessionFactory”的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“sessionFactory”的bean时出错:调用init方法失败;嵌套异常是 org.hibernate.MappingException:表 doc_group_permissions 中的关联引用了未映射的类:java.util.BitSet

以前有人遇到过这个吗?

I don't see anything in the official documentation about unsupported persistence data types, so I'm working under the assumption that types available in the Groovy language should be handled. However, for the following domain class:

class DocGroupPermissions {

   Workgroup workgroup
   Document document;
   BitSet permissions = new BitSet(2)

   void setPermissions(boolean canRead, boolean canWrite) {
       setReadPermissions(canRead)
       setWritePermissions(canWrite)
   }

   void setReadPermissions(boolean canRead) {
      permissions.set(0,canRead)
   }
   void setWritePermissions(boolean canWrite) {
      permissions.set(1,canWrite)
   }

   boolean getReadPermissions() {
      return permissions.get(0)
   }

   boolean getWritePermissions() {
      return permissions.get(1)
   }


   static belongsTo = [workgroup:Workgroup, document:Document]

   static constraints = {
      workgroup(nullable:false, blank:false)
      document(nullable:false, blank:false)
   }
}

I'm getting:

2009-11-15 16:46:12,298 [main] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table doc_group_permissions refers to an unmapped class: java.util.BitSet

Has anyone run into this before?

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

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

发布评论

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

评论(1

慕烟庭风 2024-08-17 21:38:47

并非所有类型都被映射 - 我认为这实际上是 hibernate 方面的一个问题(ORM 层需要知道如何持久化它不知道的对象)。

查看 joda-time 插件,它附带了一个映射 joda Dates 类的特殊库休眠,然后你必须在映射闭包中指定它。

您应该尝试看看是否有人为 BitSet 编写了休眠持久器,或者尝试使用不同的类。

Not all types are mapped - I think this is more of an issue from hibernate side, actually (the ORM layer needs to know how to persist the objects it doesn't know about).

Check out the joda-time plugin, it comes with a special library that maps the joda Dates classes to hibernate, and then you have to specify it in mapping closure.

You should try to see if somebody wrote a hibernate persister for BitSet, or try to use a different class.

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