2013-11-27 144 views
0

我需要映射在JPA是這樣的:如何映射雙關係JPA?

http://i.stack.imgur.com/9ve1W.png

我該如何映射兩個「表」之間的兩個關係,其中一個是主鍵和一對一(newClient提前)和其他方面,一對多對不對?

我試過類似的東西,但失敗了。

public class Recommendation implements Serializable { 
    @Id @OneToOne 
    @Column(name="...") 
    private Client newClient; 
    @ManyToOne 
    @Column(name="...") 
    private Client oldFella; 
    @Column(name="...") 
    private Boolean wasUsedToGenerateBond; 

... 

} 

謝謝!

回答

0

像這樣:

@Id @OneToOne 
@JoinColumn(name="id_client1") 
private Client newClient; 
@ManyToOne 
@JoinColumn(name="id_client2") 
private Client oldFella; 
+0

它不工作。我在類客戶端得到了如下所示:'@OneToMany(fetch = FetchType.EAGER,mappedBy =「newClient」) \t private Set recommendations = new HashSet (); \t @ManyToOne \t私人客戶端theGuyWhoRecommendsMens;' – tehAnswer

+0

它以哪種方式不起作用? –

+0

無法配置EntityManagerFactory。 'mappedBy引用一個未知的目標實體屬性:uo.ri.model.Recommendation.newClient in uo.ri.model.Cliente.recommendations' – tehAnswer