【问题标题】:Mapping Clob type in grails domain class with postgresql text type使用 postgresql 文本类型映射 grails 域类中的 Clob 类型
【发布时间】:2019-05-30 21:24:10
【问题描述】:

我使用的代码适用于 Derby、MySQL、Oracle,但在与 PostgreSQL 一起使用时抛出错误我收到错误 org.hibernet.exception.DataException 无法执行查询

我得到了一个用字符串映射文本的解决方案。 但是没有任何解决方案适用于在域类中使用 Clob 的地图文本。

class Ticket {
    String id
    String name
    String customerId
    int severity
    Clob description
    String component
    Clob screenshot

    static mapping = {
        version false
        table 'MY_TICKET'
        id generator: 'assigned'
        columns {
            id column: 'TICKET_ID'
            customerId column: 'CUSTOMER_ID'
        }
    }

    static constraints = {
        id bindable: true
    }   
}

【问题讨论】:

  • 我遵循stackoverflow.com/questions/13420081/… 的方法,所以我能够看到数据。在一个地方,我正在调用 Ticket.get(id),它在内部调用休眠反射以进行 get 调用,并且我收到错误消息 org.springframework.orm.hibernate5.HibernateSystemException:无法设置无法设置字段值 [描述] 反射类 Ticket.description 的值。

标签: hibernate spring-boot grails grails-orm grails-3.0


【解决方案1】:

需要将Clob类型改为String类型

class Ticket {
    String id
    String name
    String customerId
    int severity
    String description
    String component
    String screenshot

    static mapping = {
        version false
        table 'MY_TICKET'
        id generator: 'assigned'
        columns {
            id column: 'TICKET_ID'
            customerId column: 'CUSTOMER_ID'
        }
    }

    static constraints = {
        id bindable: true
    }  

     component sqltype:'text'
     screenshot sqltype:'text'
}

当我们需要在映射中使用 clob 类型时,我们总是将其建模为映射类型为“文本”的字符串。

【讨论】:

  • 谢谢,@Ajay 它对我有用。我看到了 sqltype 和 type 这些之间的实际区别。
猜你喜欢
  • 2011-04-30
  • 1970-01-01
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 2012-05-17
  • 1970-01-01
  • 2011-03-11
  • 1970-01-01
相关资源
最近更新 更多