问题描述
你好我有一个命名查询
@NamedQuery(name =StudyplanCategory.findByStatusAndLimit,
query = SELECT s FROM StudyplanCategory s WHERE
s.status =:status LIMIT s.start =:start,s.end = end)
我想设置这样的限制:
@NamedQuery(name = StudyplanCategory.findByStatusAndLimit,
query =SELECT s FROM StudyplanCategory s WHERE
s.status =:status LIMIT s.start =:start,s.end = end)
但是这在服务器启动时显示错误。
我使用下面的代码来调用DAO类中的查询:
$ p $ Query query = entityManager.createNamedQuery( StudyplanCategory.findByStatusAndLimit);
int end =(start * pageNumber);
query.setParameter(status,status);
query.setParameter(start,start);
query.setParameter(end,end);
return(List< StudyplanCategory>)query.getResultList();
开始和结束参数需要设置。请帮助。
@NamedQuery(name =StudyplanCategory.findByStatusAndLimit,
query =SELECT s FROM StudyplanCategory s WHERE
s.status =:status)
这会是调用命名查询的代码:
Query query = entityManager.createNamedQuery(StudyplanCategory.findByStatusAndLimit);
int end =(start * pageNumber);
query.setParameter(status,status);
query.setFirstResult(start);
query.setMaxResults(end - start);
return(List< StudyplanCategory>)query.getResultList();
Hi I have a Named Query
@NamedQuery(name = "StudyplanCategory.findByStatusAndLimit",
query = "SELECT s FROM StudyplanCategory s WHERE
s.status =:status LIMIT s.start=:start,s.end=end")
I want to set the limit like this:
@NamedQuery(name = "StudyplanCategory.findByStatusAndLimit",
query = "SELECT s FROM StudyplanCategory s WHERE
s.status =:status LIMIT s.start=:start,s.end=end")
But this is showing error at the start up of the Server.I am using the below code to call the query in the DAO class:
Query query = entityManager.createNamedQuery("StudyplanCategory.findByStatusAndLimit");
int end=(start*pageNumber);
query.setParameter("status", status);
query.setParameter("start", start);
query.setParameter("end", end);
return (List<StudyplanCategory>) query.getResultList();
Start and End Parameters needs to be set. Please Help.
As @DataNucleus said, LIMIT is not a valid keyword in JPQL. That's not the way to specify how many rows to return. This is how you do it:
@NamedQuery(name = "StudyplanCategory.findByStatusAndLimit",
query = "SELECT s FROM StudyplanCategory s WHERE
s.status =:status")
And this would be the code to call the named query:
Query query = entityManager.createNamedQuery("StudyplanCategory.findByStatusAndLimit");
int end=(start*pageNumber);
query.setParameter("status", status);
query.setFirstResult(start);
query.setMaxResults(end - start);
return (List<StudyplanCategory>) query.getResultList();
这篇关于如何为命名查询设置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!