Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/UserGuide/JPA/Basic JPA Development/Querying/Native
< EclipseLink | UserGuide | JPA | Basic JPA Development | Querying
Revision as of 15:36, 4 May 2011 by Ben.gelernter.oracle.com (Talk | contribs)
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
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();
Note: The JpaEntityManager API was added in EclipseLink 1.1.
In EclipseLink 1.0, the JpaQuery method setDatabaseQuery() could be used.