休眠映射 java Long 到 MySQL BIGINT 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3315941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:01:24  来源:igfitidea点击:

hibernate map java Long to MySQL BIGINT error

javamysqlhibernate

提问by QuanNH

i have a table with id field type BIGINT in MySQL

我在 MySQL 中有一个 id 字段类型为 BIGINT 的表

in hibernate object, i use java Long type for this field

在休眠对象中,我为此字段使用 java Long 类型

but when run program, it throw exception: Expected: class java.lang.Long, got class java.lang.Integer

但是当运行程序时,它抛出异常: Expected: class java.lang.Long, got class java.lang.Integer

how to map MySQL BINGINT datatype in hibernate ?

如何在休眠中映射 MySQL BINGINT 数据类型?

采纳答案by Pascal Thivent

but when run program, it throw exception: Expected: class java.lang.Long, got class java.lang.Integer

但是当运行程序时,它抛出异常:预期:类 java.lang.Long,得到类 java.lang.Integer

Using a Longfor a BIGINT is correct and the above error suggests that you are somehow passing an Integerwhere a Longis expected somewhere in your code. Double check your code.

Long对 BIGINT使用 a是正确的,上面的错误表明您以某种方式在代码中的某处传递了IntegeraLong预期的位置。仔细检查您的代码。

回答by mosterme

Does it help if you add a columnDefinitionlike columnDefinition = “bigint(20)″to your mapping parameters?

如果在映射参数中添加columnDefinition 之类的 columnDefinition = “bigint(20)”会有所帮助 吗?