【问题标题】:Mapping postgreSQL inetger[] data type to Grails将 postgreSQL inetger[] 数据类型映射到 Grails
【发布时间】:2016-11-23 10:25:41
【问题描述】:

在我的 postgreSQL 数据库中,我有一个数据类型为 int[] 的字段试图将其映射到 Grails 域类列 Integer[] 应用程序无法启动:

org.hibernate.type.SerializationException: could not deserialize

还有其他方法可以实现吗?

我也试过这个://insurance column: 'rs_insurance', sqlType: "integer[]"

【问题讨论】:

    标签: postgresql grails


    【解决方案1】:

    byte[] 类型是开箱即用的,并映射到相应的BLOB-type。

    如果您不满意,您可以在保存时序列化您的数组,并在加载时对其进行反序列化:

    void setValue( v ) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream()
      baos.withObjectOutputStream{ it.writeObject v }
      blob = baos.toByteArray()
    }
    
    def getValue() {
      def out = null
      if( blob ) new ByteArrayInputStream( blob ).withObjectInputStream{ out = it.readObject() }
      out
    }
    

    【讨论】:

    • 来自 DB (57,58,59,60) 的值被转换为这些值 [123, 53, 55, 44, 53, 56, 44, 53, 57, 44, 54, 48, 125] ???
    • 你做了什么?你的列是什么 sql 类型的?
    • 列类型为整数[],值为 {57,58,59,60}
    • 如果你幸运的话,这可能会起作用stackoverflow.com/questions/4332467/…
    • interger[] 是一种 postgres 人工制品类型,在其他 SQL 方言中没有类似物
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多