2012-09-05 64 views
0

更具體地說,我有3個實體(醫生,患者,處方量)。該prescripts實體有兩個外鍵是指醫生和病人。所以我想要做的是通過patid和docid找到規定。問題是我可以使用query.setParameter設置兩個參數,所以我必須做什麼?如果我想用query.setParameter在jpa中設置兩個參數,我該怎麼辦?

public List<Prescripts> findByDocid(Doctors fbd) { 

TypedQuery<Prescripts> query = em.createNamedQuery("Prescripts.findByDocid", 
Prescripts.class); 
List<Prescripts> prescripts = query.setParameter 
("docid",fbd).getResultList(); 
return prescripts; 
} 

如果你想要更多的代碼,請告訴我。

謝謝。

回答

0
List<Prescripts> prescripts = 
    query.setParameter("docid",fbd) 
     .setParameter("patid", patId) 
     .getResultList(); 

或者,如果你願意避免鏈接電話:

query.setParameter("docid",fbd); 
query.setParameter("patid", patId); 
List<Prescripts> prescripts = query.getResultList(); 
+0

謝謝你這麼多的快速回答! – BreJohn

相關問題