Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Querying/Native"

m (EclipseLink Native Query)
m (EclipseLink Native Query)
Line 1: Line 1:
 
=EclipseLink Native Query=
 
=EclipseLink Native Query=
  
 +
In addition to [[EclipseLink/UserGuide/JPA/Basic JPA Development/Querying/JPQL|JPQL]], EclipseLink rich native DatabaseQuery and Expression criteria API.
 +
 +
{{EclipseLink_API
 +
|api=org.eclipse.persistence.queries
 +
|api=org.eclipse.persistence.expressions
 +
}}
 +
 +
 +
See:
 +
* [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]
 +
* [[EclipseLink/UserGuide/Queries_(ELUG)|Queries]] in the ''EclipseLink User's Guide''
 +
 +
=== Using JpaEntityManager createQuery() API ===
 +
<source lang="java">
 +
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();
 +
 +
</source>
 +
 +
{{EclipseLink_Note
 +
|note=The '''JpaEntityManager''' API was added in EclipseLink 1.1.
 +
 +
In EclipseLink 1.0, the JpaQuery method '''setDatabaseQuery()''' could be used.
 +
}}
  
  

Revision as of 13:37, 16 June 2010

EclipseLink Native Query

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


Elug api package icon.png Key API {{{apis}}}


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();

Elug note icon.png

Note: The JpaEntityManager API was added in EclipseLink 1.1.

In EclipseLink 1.0, the JpaQuery method setDatabaseQuery() could be used.


Eclipselink-logo.gif
Version: DRAFT
Other versions...