日期:2014-05-19 浏览次数:20733 次
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
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();
}