Talk:Jakarta Persistence Query Language
Appearance
![]() | Java Stub‑class Low‑importance | |||||||||
|
Mistake in example?
This article currently has the following example:
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.apache.commons.lang.StringUtils;
...
@SuppressWarnings("unchecked")
public List<Author> getAuthorsByLastName(String lastName) {
String queryString = "SELECT a FROM Author a " +
"WHERE :lastName IS NULL OR LOWER(a.lastName) = :lastName";
Query query = getEntityManager().createQuery(queryString);
query.setParameter("lastName", StringUtils.lowerCase(lastName));
return query.getResultList();
}
(Keep in mind the Author class has a field private String firstName
.)
The WHERE :lastName IS NULL
part doesn't make sense to me. Shouldn't it be written WHERE lastName IS NULL
(i.e., without the colon)? In case I'm wrong, can someone please explain the semantics of this query? --Abdull (talk) 15:20, 29 September 2012 (UTC)