2011-12-18 179 views
0

參考URL http://docs.jboss.org/hibernate/core/3.5/reference/en/html_single/,部分1.2.4休眠JPA詮釋特定列映射

它定義在hibernate配置一組。

<set name="emailAddresses" table="PERSON_EMAIL_ADDR"> 
    <key column="PERSON_ID"/> 
    <element type="string" column="EMAIL_ADDR"/> 
</set> 

如何將其轉換爲JPA註釋?

我不明白,是這樣的嗎?

@OneToMany 
@JoinTable(
    name="PERSON_EMAIL_ADDR" 
    , joinColumns={ 
     @JoinColumn(name="person_id") 
    }) 
private Set<String> emailAdresses; 

回答

2

對於Set<String>你需要@ElementCollection而不是@OneToMany(映射實體而不是值)

+1

+1。有關示例,請參閱http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#collections-ofvalues – 2011-12-18 19:30:44