Passing two parameters to a named query

前端 未结 1 770
孤独总比滥情好
孤独总比滥情好 2021-01-21 17:48

I have the following namedquery over my entity \"Intervention \":

 @NamedQuery(name = \"Intervention.findNextMission\", query = \" SELECT i FROM Intervention  i         


        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 18:25

    setParameter accepts either (int position,Object value) or (String parameterName,Object value). So your code could look as:

    Date aDate=....
    Long anId=....   
    List ListOfInterventions = em.createNamedQuery("Intervention.findNextMission")
      .setParameter("DateToBeSpecified",aDate,avax.persistence.TemporalType,DATE)
      .setParameter("idAgent",anId).getResultList();
    

    Note that when you use a Date you should specify the TemporalType intended.

    0 讨论(0)
提交回复
热议问题