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

From Eclipsepedia

Jump to: navigation, search
m
Line 33: Line 33:
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Criteria|Criteria]]
+
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Criteria|Criteria API]]
 
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query Hints|Query Hints]]
 
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query Hints|Query Hints]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying|Querying]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying|Querying]]
|version=2.2.0 DRAFT}}
+
|version=2.4 DRAFT}}

Revision as of 11:17, 5 June 2012

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source


Native SQL Queries

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

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: 2.4 DRAFT
Other versions...