2013-04-03 90 views
0

我需要連接3個表:JPA三聯「@JoinTable」註釋

doc  
-------- 
id 
id_user  


user  
-------- 
id 
id_firm 

firm  
--------  
id 

在SQL中,它提供了:

SELECT * FROM DOC d join USER u on d.id_user=u.id join FIRM f on f.id=u.id_firm 

我嘗試:

@JoinTable(name = "user", 
    joinColumns = { @JoinColumn(name = "id_user", referencedColumnName = "id") }) 

,但它不沒有用(無限循環)。

回答

0

使用inverseJoinColumns

@OneToMany(fetch=FetchType.EAGER) 
@JoinTable(name = "user", 
joinColumns   = { @JoinColumn(name = "ID_USER") }, 
inverseJoinColumns = { @JoinColumn(name = "ID_FIRM") })