2010-09-29 97 views
3
@ManyToOne(fetch = FetchType.LAZY) 
@JoinColumn (name = "account_id") 
private Account account; 

工作正常。休眠JoinColumn默認名稱缺少'_id'

@ManyToOne(fetch = FetchType.LAZY) 
@JoinColumn 
private Account account; 

結果:Exception : Missing column account in SomeSchema.SomeOwnerTable

JPA規範說默認的聯接的列名是

property name ('account') + '_' + target table primary key ('id') 

但它看起來像Hibernate是搜索剛剛任命的,而不是 'ACCOUNT_ID' 賬戶'的屬性。

有何評論?

回答

4

我認爲你可以安全地擺脫@JoinColumn註解 - 無論如何都有一個連接列。

此外,請確保您沒有配置特定的命名策略,這可能會覆蓋默認行爲。

+1

我正在使用ImprovedNamingStrategy。 ImprovedNamingStrategy轉換,例如Account - > account,accountId - > account_id。 – drypot 2010-09-29 05:57:36

+4

ImprovedNamingStrategy是問題所在。謝謝。 http://matthew.mceachen.us/blog/hibernate-naming-strategies-20.html – drypot 2010-09-29 06:00:24

+0

+1不錯的一個(pad) – 2010-09-29 06:03:56