Jump to content

Talk:Jakarta Persistence Query Language

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Abdull (talk | contribs) at 15:20, 29 September 2012 (Mistake in example?: new section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Stub‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.

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)[reply]