![](/img/trans.png)
[英]How is my id being generated with JPA using Hibernate with the Oracle 10g dialect?
[英]Why is a sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?
我的所有實體都使用這種類型的@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方言。
HIBERNATE_SEQUENCE與REVINFO實體一起用於創建修訂號。 如果要使用不同的序列,則應創建自定義修訂實體。
幫助: http : //docs.jboss.org/hibernate/envers/3.5/reference/en-US/html/revisionlog.html
我在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
沒有“正確”注釋。 也許你應該執行一些調試會話。
我懷疑這是因為我正在使用Hibernate Envers,因為我已經對我的實體進行了雙重檢查,並且所有這些實體都具有正確的@Id映射。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.