Grails/GORM BigInteger无符号拒绝

Grails/GORM BigInteger无符号拒绝,grails,groovy,gorm,Grails,Groovy,Gorm,我得到以下错误: | Error 2014-08-18 11:25:00,324 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Validation Error(s) occurred during save(): - Field error in object 'my.package.Content' on field 'fileN

我得到以下错误:

| Error 2014-08-18 11:25:00,324 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Validation Error(s) occurred during save():
- Field error in object 'my.package.Content' on field 'fileNameLookup': rejected value [16731516642733300018]; codes [my.package.Content.fileNameLookup.typeMismatch.error,my.package.Content.fileNameLookup.typeMismatch,content.fileNameLookup.typeMismatch.error,content.fileNameLookup.typeMismatch,typeMismatch.my.package.Content.fileNameLookup,typeMismatch.fileNameLookup,typeMismatch.java.lang.Long,typeMismatch]; arguments [fileNameLookup]; default message [Could not convert number [16731516642733300018] of type [java.math.BigInteger] to target class [java.lang.Long]: overflow]
Message: Validation Error(s) occurred during save():
- Field error in object 'my.package.Content' on field 'fileNameLookup': rejected value [16731516642733300018]; codes [my.package.Content.fileNameLookup.typeMismatch.error,my.package.Content.fileNameLookup.typeMismatch,content.fileNameLookup.typeMismatch.error,content.fileNameLookup.typeMismatch,typeMismatch.my.package.Content.fileNameLookup,typeMismatch.fileNameLookup,typeMismatch.java.lang.Long,typeMismatch]; arguments [fileNameLookup]; default message [Could not convert number [16731516642733300018] of type [java.math.BigInteger] to target class [java.lang.Long]: overflow]
Line | Method
->>    6 | doCall                           in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    320 | executeForEnvironment . . . . .  in     ''
|    296 | executeForCurrentEnvironment     in     ''
|    266 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1142 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                              in java.lang.Thread
Error |
Forked Grails VM exited with error
域类:

    package my.package

// need to fix constraints

class Content {
    // int id
    Long fileNameLookup

    static mapping = {
        version false
        fileNameLookup column: 'file_name_lookup', type:org.hibernate.type.LongType, class: Long
    }

    static constraints = {
        fileNameLookup(nullable:true, display:false, editable: false)
    }
}
Bootstrap.groovy:

import my.package.Content

class BootStrap {

    def init = { servletContext ->
        new Content(fileNameLookup:16731516642733300018).save(failOnError:true)
    }
    def destroy = {
    }
}

我试过Long,biginger,Integer等等。。。为了找出如何将这个bigint20 unsigned保存到测试数据库中,花了好几个小时。如何告诉Grails/Gorm该数字是一个bigint20,以便无论我使用的是哪个数据库,它都能正确处理它?

Long.MAX_值是9223372036854775807。你的号码太大了。使用BigDecimal应该可以解决这个问题

BigDecimal fileNameLookup

你有没有试过一个适合长期使用的号码?正如错误所说,16731516642733300018太大,无法放入长文件,因此您会溢出。感谢您指出,我想知道的是正确的类型,以便我可以在数据库中放入该大小的数字。错误消息告诉您,长文件名查找字段太小,无法存储该数字。将类型更改为java.math.BigInteger是否会给您带来不同的错误消息?使用H2数据库,我无法让它工作,我知道它可以与MySQL一起工作,因为我用来生成20位数字的代码最初是为MySQL开发的。我编写了一个groovy类来为我处理转换,这样我就可以使用任何数据库,而不必让代码只依赖于MySQL。更改数据源后,我所做的是向映射添加sqlType:“bigint20 unsigned”。我真的很想让它适用于任何数据库,但该字段对于H2中的任何字段都太长。某些数据库不支持无符号bigint列类型,H2就是其中之一。我尝试了您的建议,但仍然出现错误。我不知道为什么我必须把一个bigint20保存为十进制。grails/gorm中没有bigint类型吗?我继续尝试了一下,这次我添加了sqlType:'decimal20,0',它成功了。我不确定我是否喜欢这种将其视为数字的方法,而不是将其视为查询中where子句中使用的整数。我最终希望使用一个不带签名的bigint20,而不考虑平台。