Jump to: navigation, search

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

(New page: In addition to JPQL, EclipseLink defines a rich DatabaseQuery and Expression criteria API. See: * [http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/queries/package-frame...)
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:EclipseLink/Example/JPA|DatabaseQuery]]
 +
 
In addition to JPQL, EclipseLink defines a rich DatabaseQuery and Expression criteria API.
 
In addition to JPQL, EclipseLink defines a rich DatabaseQuery and Expression criteria API.
  
Line 4: Line 6:
 
* [http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/queries/package-frame.html org.eclipse.persistence.queries]
 
* [http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/queries/package-frame.html org.eclipse.persistence.queries]
 
* [http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/expressions/package-frame.html org.eclipse.persistence.expressions]
 
* [http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/expressions/package-frame.html org.eclipse.persistence.expressions]
* [[http://wiki.eclipse.org/EclipseLink/UserGuide/Queries_(ELUG)|Queries]] in the ''EclipseLink User's Guide''
+
* [[EclipseLink/UserGuide/Queries_(ELUG)|Queries]] in the ''EclipseLink User's Guide''
  
== Using JpaEntityManager createQuery() API ==
+
=== Using JpaEntityManager createQuery() API ===
 
<source lang="java">
 
<source lang="java">
 +
import javax.persistence.Query;
 +
import org.eclipse.persistence.expressions.*;
 +
import org.eclipse.persistence.queries.ReadAllQuery;
 +
 
ExpressionBuilder builder = new ExpressionBuilder();
 
ExpressionBuilder builder = new ExpressionBuilder();
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class, builder);
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class, builder);

Latest revision as of 17:13, 25 November 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.