Content deleted Content added
Reverted to original example! Example without Author as Class does not make sense for the JPQL Query Examples (they are not understandable if the Author Class is not known)! |
m Disambiguating links to Object-orientation (link changed to Object-oriented programming) using DisamAssist. |
||
(24 intermediate revisions by 15 users not shown) | |||
Line 1:
{{
{{Infobox programming language
| name =
| logo =
| paradigm =
Line 11:
| latest_test_version =
| latest_test_date =
| typing =
| implementations =
| dialects =
| influenced_by = [[SQL]], [[Hibernate (Java)#Hibernate Query Language (HQL)|Hibernate]]
| influenced =
| operating_system = [[Cross-platform]]
Line 21 ⟶ 20:
| website =
}}
The '''
JPQL is used to make queries against entities stored in a relational database. It is heavily inspired by [[SQL]], and its queries resemble SQL queries in syntax,{{sfn|Bauer|King|Gregory|2016}}{{rp|loc=§1.3|p=17}} but operate against JPA entity objects rather than directly with database tables.{{sfn|Bauer|King|Gregory|2016}}{{rp|loc=§2.2.3|p=26}}
In addition to retrieving objects (<code>SELECT</code> queries), JPQL supports set based <code>UPDATE</code> and <code>DELETE</code> queries.
Line 31 ⟶ 30:
Example JPA Classes, getters and setters omitted for simplicity.
<
@Entity
public class Author {
Line 67 ⟶ 66:
private List<Book> books;
}
</syntaxhighlight>
Then a simple query to retrieve the list of all authors, ordered alphabetically, would be:
<
SELECT a FROM Author a ORDER BY a.firstName, a.lastName
</syntaxhighlight>
To retrieve the list of authors that have ever been published by XYZ Press:
<
SELECT DISTINCT a FROM Author a INNER JOIN a.books b WHERE b.publisher.name = 'XYZ Press'
</syntaxhighlight>
JPQL supports named parameters, which begin with the colon (<code>:</code>). We could write a function returning a list of authors with the given last name as follows:
<
import javax.persistence.EntityManager;
import javax.persistence.
...
public List<Author> getAuthorsByLastName(String lastName) {
String queryString = "SELECT a FROM Author a " +
"WHERE
query.setParameter("lastName",
return query.getResultList();
}
</syntaxhighlight>
==Hibernate Query Language==
JPQL is based on the [[
Hibernate and the HQL were created before the JPA specification.
As of Hibernate 3 JPQL is a subset of HQL.
==Citations==
{{Reflist}}
==References==
*{{citation
|last1 = Bauer
|first1 = Christian
|last2 = King
|first2 = Gavin
|last3 = Gregory
|first3 = Gary
| year = 2016
| title = Java Persistence with Hibernate
| edition = Second
| publisher = [[Manning Publications]]
| isbn = 978-1617290459
| url =
}}
==See also==
* [[Object-relational mapping]]
* [[Hibernate (
* [[
== External links ==
* {{official website}}
** [
* [
* [
{{
[[Category:Query languages]]
[[Category:Data modeling languages]]
[[Category:Java enterprise platform]]
|