Difference between revisions of "EclipseLink/Examples/JPA/DatabaseQuery"

From Eclipsepedia

Jump to: navigation, search
Line 9: Line 9:
 
<source lang="java">
 
<source lang="java">
 
import javax.persistence.Query;
 
import javax.persistence.Query;
import org.eclipse.persistence.expression.*;
+
import org.eclipse.persistence.expressions.*;
 
import org.eclipse.persistence.queries.ReadAllQuery;
 
import org.eclipse.persistence.queries.ReadAllQuery;
  

Revision as of 14:11, 12 March 2009

In addition to JPQL, EclipseLink defines a rich DatabaseQuery and Expression criteria API.

See:

Using JpaEntityManager createQuery() API

import javax.persistence.Query;
import org.eclipse.persistence.expressions.*;
import org.eclipse.persistence.queries.ReadAllQuery;
 
ExpressionBuilder builder = new ExpressionBuilder();
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class, builder);
databaseQuery.setSelectionCriteria(builder.get("firstName").like("B%"));
databaseQuery.addOrdering(builder.get("firstName").toUpperCase());
 
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(databaseQuery);
List result = query.getResultList();

This JpaEntityManager API was added in EclipseLink 1.1, in EclipseLink 1.0, the JpaQuery method setDatabaseQuery() could be used.