【问题标题】:What does hibernate do with generator class="native" on oracle db?hibernate 对 oracle db 上的 generator class="native" 有什么作用?
【发布时间】:2011-11-04 09:21:44
【问题描述】:

我的代码中有这个映射:

新闻.hbm.xml: 其余的映射

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

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

这对 Oracle 意味着什么?

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

【问题讨论】:

  • 这个link 可以帮助你。

标签: oracle hibernate


【解决方案1】:

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

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

// 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);
        }
    }
}

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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-27
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 2014-03-23
      • 2015-08-05
      • 2022-08-11
      相关资源
      最近更新 更多