Why is a sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?

守給你的承諾、 提交于 2019-12-04 20:49:34

问题


All my entities use this type of @Id

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

or

@Id
@Column(name = "MYENTITY")

I find that an Oracle sequence named hibernate_sequence is always created. Why is this so? And how can I avoid this?

I am using JPA1 with Hibernate 3 and the Oracle 10g dialect.


回答1:


The HIBERNATE_SEQUENCE is used with REVINFO-entity for creating revision numbers. If you want to use different sequence you should create your custom revision entity.

Help with that: http://docs.jboss.org/hibernate/envers/3.5/reference/en-US/html/revisionlog.html




回答2:


I see the following code in 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 );
}

Where the third parameter of PropertiesHelper.getString(String, Properties, String) is the default property value.

So I'm tempted to say that, somewhere, you have an Id not "properly" annotated. Maybe you should perform a little debugging session.




回答3:


I suspect it's because i am using Hibernate Envers as i've double checked my entities and all of them have the correct @Id mappings.



来源:https://stackoverflow.com/questions/3058251/why-is-a-sequence-named-hibernate-sequence-being-created-with-jpa-using-hibernat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!