Hibernate的 - 如何提供正确的映射到整​​数类型? [英] Hibernate - How to provide right mapping to integer type?

查看:105
本文介绍了Hibernate的 - 如何提供正确的映射到整​​数类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最后一个原因:列类型为x.clients的列类型错误。 Found:tinyint,expected:integer



我是这样映射的:

  @Id 
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

我使用InnoDB创建列如下: id int NOT NULL UNIQUE AUTO_INCREMENT



这不应该好吗?为什么说他在找tinyint?

解决方案

使用 @ Basic 为基本整数。您可以随时尝试将您的ID声明为Long。我通常总是使用Long作为我的ID。请参阅映射标识符特征

  @Id 
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;


I'm executing my maven build and it throws this exception:

Last cause: Wrong column type in x.clients for column type. Found: tinyint, expected: integer

I'm mapping like this:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

And I'm creating the column using InnoDB like this: id int NOT NULL UNIQUE AUTO_INCREMENT

Shouldn't this be ok? Why is it saying that he is finding tinyint?

解决方案

Use @Basic for basic integers. You can always trying declaring your ID as a Long though. I usually always use Long for my IDs. See Mapping Identifier Properities:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

这篇关于Hibernate的 - 如何提供正确的映射到整​​数类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆