本文介绍了hibernate在启动时创建空表 - hibernate_sequence的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚下载了hibernate 5.0.0.1,并且我尝试了我的项目,它以前使用hibernate 4.3。

当我插入数据库时​​,它给我这个错误:
$ b

我正在使用mysql,并且我的生成策略设置为GenerationType.auto,现在看起来hibernate认为使用序列是生成值的最佳策略。但桌子是空的。我认为hibernate试图从序列中获取一个值,但找不到任何值。但是我很困惑,因为hibernate_sequence是由hibernate创建的,它不应该提供一个初始值吗?解析方案

序列表是因为你如何定义了一个/所有实体的主键。

  @Id 
@ GeneratedValue(strategy = GenerationType.AUTO)//或GenerationType.SEQUENCE
保护长ID;

如果您想使用表格的标识列:

  @Id 
@GeneratedValue(strategy = GenerationType.IDENTITY)
保护长ID;

您可以查看以下线索以获取更多信息:


So I just downloaded hibernate 5.0.0.1, and I tried my project to it, which is previously using hibernate 4.3.

When I insert to the database, it gives me this error:

I am using mysql, and my generation strategy is set at GenerationType.auto, and it seems that now hibernate thinks using sequences is the best strategy for generating values. But the table is empty. I think hibernate is atempting to get a value from the sequence but can't find any. But I'm confused because the hibernate_sequence is created by hibernate, shouldn't it provide an initial value?

解决方案

The sequence table is because of how you've defined the primary key on one/all of your entities.

@Id
@GeneratedValue(strategy = GenerationType.AUTO) // or GenerationType.SEQUENCE
protected Long id;

If you want to use a table's identity column:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;

You might to check this thread for more information:https://forums.hibernate.org/viewtopic.php?f=1&t=999785&start=0

这篇关于hibernate在启动时创建空表 - hibernate_sequence的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:16