Content deleted Content added
Tags: Mobile edit Mobile web edit |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 31:
Example JPA Classes, getters and setters omitted for simplicity.
<
@Entity
public class Author {
Line 67:
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.TypedQuery;
Line 97:
return query.getResultList();
}
</syntaxhighlight>
==Hibernate Query Language==
|