JPA - Could not locate named parameter
I try to delete rows from a table that lived more than a given time in
days. The start of a row is a timestamp.
EntityManager em = ...
long interval = ... // long value read from a properties file
String template = "DELETE FROM %s WHERE currentTimestamp - start >
:interval";
String jpql = String.format(template , MyClass.class.getCanonicalName());
Query q = em.createQuery(jpql);
q.setParameter("interval", TimeUnit.DAYS.toMillis(interval));
q.executeUpdate();
MyClass.java
@Entity
@Table(name = "ROWS")
public class MyClass implements Serializable {
private static final long serialVersionUID = 6070604872038740340L;
puyblic MyClass() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
However, I get the following exception :
org.hibernate.QueryParameterException: could not locate named parameter
[interval]
What am I doing wrong ?
No comments:
Post a Comment