我有一个基于 JPA 的项目,如下所示:
@Entity
@Table(name="events")
public class Event implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String data;
@Temporal(TemporalType.TIMESTAMP)
private java.util.Date eventDate;
/* ... getters & setters */
}
在我的 DAO 中,我这样做:
public void checkForEvents(String text, java.util.Date myDate) {
String query = "SELECT e FROM Event e WHERE e.data LIKE '%?1%' AND e.eventDate > ?2";
Query q = getEntityManager().createQuery(query);
q.setParameter(1, text);
q.setParameter(2, myDate);
q.getSingleResult() /* and so on ... */
}
当我运行 DAO 代码时,我收到此错误:
The parameter "0" is of type "java.lang.String", but the declaration in the query is for type "java.util.Date".
我究竟做错了什么?