Java Hibernate_sequence表生成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41461283/
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
Hibernate_sequence table is generated
提问by Vitalii Kravchenko
I have id column with generated strategy AUTO, I'm wondering, why MySql generate hibernate_sequence table? I supposed that hibernate will pick IDENTITY id generating strategy
我有带有生成策略 AUTO 的 id 列,我想知道,为什么 MySql 生成 hibernate_sequence 表?我认为 hibernate 会选择 IDENTITY id 生成策略
<mapped-superclass class="com.cl.xlp.model.data.Identity">
<attributes>
<id name="id">
<column name="id" />
<generated-value strategy="AUTO" />
</id>
</attributes>
</mapped-superclass>
Hibernate properties
休眠属性
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
Mysql connector version
Mysql 连接器版本
version.mysql.connector>5.1.39</version.mysql.connector>
Mysql server version is 5.6.12
Mysql服务器版本是5.6.12
回答by Poly
If you use strategy="AUTO"
, Hibernate will generate a table called hibernate_sequence
to provide the next number for the ID
sequence. You may have forgotten to add the AutoIncrement
feature to your table's PK.
如果您使用strategy="AUTO"
,Hibernate 将生成一个表,称为hibernate_sequence
提供ID
序列的下一个编号。您可能忘记将该AutoIncrement
功能添加到您的表的 PK 中。
You may use generation strategy strategy="IDENTITY"
to enforce using the AutoIncrement
feature available in MySql and avoid creating a table.
您可以使用生成策略strategy="IDENTITY"
来强制使用AutoIncrement
MySql 中可用的功能并避免创建表。
回答by Kamalesh Patil
The way Hibernate interprets AUTO generation type has changed starting with Hibernate version 5.0.
从 Hibernate 5.0 版开始,Hibernate 解释 AUTO 生成类型的方式发生了变化。
When using Hibernate v 4.0 and Generation Type as AUTO
, specifically for MySql, Hibernate would choose the IDENTITY
strategy (and thus use the AUTO_INCREMENT
feature) for generating IDs for the table in question.
当使用 Hibernate v 4.0 和 Generation Type as 时AUTO
,特别是对于 MySql,Hibernate 会选择IDENTITY
策略(并因此使用该AUTO_INCREMENT
功能)来为相关表生成 ID。
Starting with version 5.0 when Generation Type is selected as AUTO, Hibernate uses SequenceStyleGenerator
regardless of the database. In case of MySql Hibernate emulates a sequence using a table and is why you are seeing the hibernate_sequence table. MySql doesn't support the standard sequence type natively.
从 5.0 版本开始,当 Generation Type 选择为 AUTO 时,Hibernate 使用SequenceStyleGenerator
而不考虑数据库。在 MySql Hibernate 使用表模拟序列的情况下,这就是您看到 hibernate_sequence 表的原因。MySql 本身不支持标准序列类型。
References
参考