休眠对 oracle db 上的生成器 class="native" 有何作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7202764/
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-09-10 03:29:44  来源:igfitidea点击:

What does hibernate do with generator class="native" on oracle db?

oraclehibernate

提问by Ula Krukar

I have this mapping in my code:

我的代码中有这个映射:

News.hbm.xml:
<class name="xyz.News" table="XYZ_NEWS">
        <id name="id" column="NEWS_ID">
            <generator class="native"/>
        </id>
rest of mapping
</class>

I am using Oracle database. Hibernate documentation tells me:

我正在使用 Oracle 数据库。Hibernate 文档告诉我:

native - selects identity, sequence or hilo depending upon the capabilities of the underlying database

native - 根据底层数据库的功能选择身份、序列或 hilo

What does that mean for Oracle?

这对 Oracle 意味着什么?

Edit:I know now it uses sequences. The name of the sequence is what i am interested in.

编辑:我知道现在它使用序列。序列的名称是我感兴趣的。

回答by Stefan Steinegger

It takes sequences. You need to provide a sequence name.
Edit: If name is not provided, sequence named HIBERNATE_SEQUENCEis going to be used.

它需要序列。您需要提供序列名称。
编辑:如果未提供名称,将使用名为HIBERNATE_SEQUENCE 的序列。

Looking at the code, it lets the dialect decide. The Dialect implements the decision like this:

查看代码,它让方言决定。方言执行这样的决定:

// Dialect.cs Line 231
public virtual System.Type NativeIdentifierGeneratorClass
{
    get
    {
        if (SupportsIdentityColumns)
        {
            return typeof(IdentityGenerator);
        }
        else if (SupportsSequences)
        {
            return typeof(SequenceGenerator);
        }
        else
        {
            return typeof(TableHiLoGenerator);
        }
    }
}

It isn't overriden by Oracle. Oracle doesn't support identity, but sequences.

它不会被 Oracle 覆盖。Oracle 不支持身份,但支持序列。

回答by danny.lesnik

It's quite simple: Your generator will use identity or sequence columns according to what your current database support:

这很简单:您的生成器将根据您当前的数据库支持使用标识或序列列:

For example Oracle has sequences but previous versions of MS SQL server don't.

例如,Oracle 有序列,但以前版本的 MS SQL 服务器没有。

You can read more about differences between identities and sequences in this article: http://sqlserver-training.com/what-is-the-difference-between-identity-and-sequence/-

您可以在本文中阅读有关身份和序列之间差异的更多信息:http: //sqlserver-training.com/what-is-the-difference-between-identity-and-sequence/-

The native generator always returns long, short or integer values:

本机生成器始终返回长、短或整数值: