2011-03-14 106 views
0

我有兩個用於複合鍵的遺留數據庫的實體,其中一個具有@EmbeddedId註釋的複合鍵。帶複合鍵的加入實體

// first entity 
@Entity 
public class Product { 

@Id 
private Integer productId; 

// lookup table contains code-description pairs 
@OneToOne 
private ProductDefects defects; 

//getters and setters and other code omitted 

} 

// lookup entity 
@Entity 
public class ProductDefects { 

@EmbededId 
private ProductDefectsPK id; 

//getters and setters and other code omitted 

} 

//composite key 
@Embedable 
public class ProductDefectsPk{ 
    private Integer realId; 
    private String category; 
} 

我應該如何界定@OneToOne關係加入如下面的例子:

select p.Id, pd.description 
from Product p 
inner join p.defects pd 
+0

現在我不明白你的問題。你想寫一個特定的JPQL查詢嗎? – Behrang 2011-03-15 13:38:03

+0

JPQL像這樣select p.Id,pd.description from Products p join f.defects pd – 2011-03-15 14:02:06

回答