简体   繁体   English

生成Hibernate_sequence表

[英]Hibernate_sequence table is generated

I have id column with generated strategy AUTO, I'm wondering, why MySql generate hibernate_sequence table? 我有生成策略AUTO的id列,我想知道,为什么MySql生成hibernate_sequence表? I supposed that hibernate will pick IDENTITY id generating strategy 我认为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属性

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

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作为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. 从版本5.0开始,当Generation Type被选为AUTO时,无论数据库如何,Hibernate都使用SequenceStyleGenerator In case of MySql Hibernate emulates a sequence using a table and is why you are seeing the hibernate_sequence table. 在MySql的情况下,Hibernate使用表模拟一个序列,这就是你看到hibernate_sequence表的原因。 MySql doesn't support the standard sequence type natively. MySql本身不支持标准序列类型。

References 参考

If you use strategy="AUTO" , Hibernate will generate a table called hibernate_sequence to provide the next number for the ID sequence. 如果使用strategy="AUTO" ,Hibernate将生成一个名为hibernate_sequence的表,为ID序列提供下一个数字。 You may have forgotten to add the AutoIncrement feature to your table's PK. 您可能忘记将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"来强制使用MySql中提供的AutoIncrement功能,并避免创建表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM