Java 为什么使用带有 Oracle 10g 方言的 Hibernate 使用 JPA 创建名为 hibernate_sequence 的序列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3058251/
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
Why is a sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?
提问by JavaRocky
All my entities use this type of @Id
我所有的实体都使用这种类型的 @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?
我发现hibernate_sequence
总是会创建一个名为 Oracle 的序列。为什么会这样?我怎样才能避免这种情况?
I am using JPA1 with Hibernate 3 and the Oracle 10g dialect.
我在 Hibernate 3 和 Oracle 10g 方言中使用 JPA1。
采纳答案by JavaRocky
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.
我怀疑这是因为我正在使用 Hibernate Envers,因为我已经仔细检查了我的实体,并且所有实体都具有正确的 @Id 映射。
回答by Pascal Thivent
I see the following code in org.hibernate.id.SequenceGenerator
:
我在以下代码中看到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.
其中第三个参数PropertiesHelper.getString(String, Properties, String)
是默认属性值。
So I'm tempted to say that, somewhere, you have an Id
not "properly" annotated. Maybe you should perform a little debugging session.
所以我很想说,在某处,您Id
没有“正确”注释。也许您应该执行一些调试会话。
回答by Matias Sundberg
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.
HIBERNATE_SEQUENCE 与 REVINFO 实体一起用于创建修订号。如果您想使用不同的序列,您应该创建您的自定义修订实体。
Help with that: http://docs.jboss.org/hibernate/envers/3.5/reference/en-US/html/revisionlog.html
帮助:http: //docs.jboss.org/hibernate/envers/3.5/reference/en-US/html/revisionlog.html