grails - GRAILS将ID类型更改为 'int'后,我无法再创建对象

标签 grails gorm create-table

在我们的旧版系统(MSSQL)中,我们将int用作id的类型,并且我不想干扰它,因此我更改了这种类型:

static mapping  = {
    id              column: "id",              type:        'int'

但是,在我创建一些示例记录的 bootstrap 中,它不再起作用。
错误信息:
Configuring Spring Security UI ...
... finished configuring Spring Security UI

2017-03-04 10:31:20.381 ERROR --- [           main] o.h.p.access.spi.SetterMethodImpl        : HHH000123: IllegalArgumentException in class: com.buffer.ProdBuffer, setter method of property: id
2017-03-04 10:31:20.385 ERROR --- [           main] o.h.p.access.spi.SetterMethodImpl        : HHH000091: Expected type: java.lang.Long, actual value: java.lang.Integer
2017-03-04 10:31:20.419 ERROR --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.orm.hibernate5.HibernateSystemException: IllegalArgumentException occurred while calling setter for property [com.buffer.ProdBuffer.id (expected type = java.lang.Long)]; target = [com.buffer.ProdBuffer : (unsaved)], property value = [1] setter of com.buffer.ProdBuffer.id; nested exception is IllegalArgumentException occurred while calling setter for property [com.buffer.ProdBuffer.id (expected type = java.lang.Long)]; target = [com.buffer.ProdBuffer : (unsaved)], property value = [1]
    at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:296)
    at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:661)
    at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:247)
    at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:187)

好像我错过了某件事...除了改变“静态映射”中的类型,我还需要做更多的事情吗?

该类(class)的一部分:
class ProdBuffer {
     String status
    String product
    String length
    int    productNo

    static mapping  = {
        table 'LOBuffertv2'
        id              column: "id",              type:        'integer'
        product     column: "Produkt",         sqltype: "char", length: 150
        length      column: "Length",          sqltype: "char", length: 25
        productNo       column: "ProductNo"
    }
    static constraints = {
        status(inList:["Preliminary","Activ","Finished","Cancelled"])
        status                  nullable: true
        product                 nullable: true
        length                  nullable: true
        productNo               nullable: true       
    }
}

最佳答案

我建议您更改数据库中的表以将ID作为BIGINT(20)处理。并从域类定义和映射中删除ID。 Gorm将为您完成剩下的工作。

关于grails - GRAILS将ID类型更改为 'int'后,我无法再创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42594517/

相关文章:

mongodb - Grails 3使用_id和id保存mongoDB文档

validation - Grails域对象在验证期间意外保存

mysql - 如何使用 create-select 语句设置列类型

grails - 自添加数据库连接以来,Grails运行应用程序时出错

登录和注销后,Spring Security 重定向回引用 URL

grails - Grails 2.5.0持久对象的空ID

Mysql,无法创建表

grails - 为什么将服务命名为 "service"在集成测试中不起作用?

authentication - 如何在Grails应用程序中显示CAS身份验证用户名

php - 在 MySQL 中创建外键