【问题标题】:Why is a sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?为什么使用带有 Oracle 10g 方言的 Hibernate 使用 JPA 创建名为 hibernate_sequence 的序列?
【发布时间】:2011-03-04 17:58:08
【问题描述】:

我所有的实体都使用这种类型的@Id

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYENTITY_SEQ")
@SequenceGenerator(name = "MYENTITY_SEQ", sequenceName = "MYENTITY_SEQ")
@Column(name = "MYENTITY", nullable = false)
private Long id;

@Id
@Column(name = "MYENTITY")

我发现总是会创建一个名为 hibernate_sequence 的 Oracle 序列。为什么会这样?我该如何避免这种情况?

我将 JPA1 与 Hibernate 3 和 Oracle 10g 方言一起使用。

【问题讨论】:

  • 你确定没有任何@Entity 的 id 用@GeneratedValue() 注释而没有声明属性吗???

标签: java hibernate orm jpa oracle10g


【解决方案1】:

我在org.hibernate.id.SequenceGenerator看到如下代码:

public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
    ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
    sequenceName = normalizer.normalizeIdentifierQuoting(
            PropertiesHelper.getString( SEQUENCE, params, "hibernate_sequence" )
    );
    parameters = params.getProperty( PARAMETERS );

    if ( sequenceName.indexOf( '.' ) < 0 ) {
        final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) );
        final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) );
        sequenceName = Table.qualify(
                dialect.quote( catalogName ),
                dialect.quote( schemaName ),
                dialect.quote( sequenceName )
        );
    }
    else {
        // if already qualified there is not much we can do in a portable manner so we pass it
        // through and assume the user has set up the name correctly.
    }

    this.identifierType = type;
    sql = dialect.getSequenceNextValString( sequenceName );
}

其中PropertiesHelper.getString(String, Properties, String)的第三个参数是默认属性值。

所以我很想说,在某个地方,你有一个 Id 没有“正确”注释。或许您应该执行一些调试会话。

【讨论】:

    【解决方案2】:

    我怀疑这是因为我使用的是 Hibernate Envers,因为我已经仔细检查了我的实体并且它们都具有正确的 @Id 映射。

    【讨论】:

    • 解决方案是什么?
    【解决方案3】:

    HIBERNATE_SEQUENCE 与 REVINFO 实体一起用于创建修订号。如果您想使用不同的序列,您应该创建您的自定义修订实体。

    帮助: http://docs.jboss.org/hibernate/envers/3.5/reference/en-US/html/revisionlog.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-10
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 2017-06-03
      • 2015-06-11
      相关资源
      最近更新 更多