There are several JPAs “how to” that we can find on the internet, here in this blog, that teaches how to do several tasks with JPA.
Usually I see some people asking questions about Queries with JPA; usually to answer this kind of questions several links are provided trying to find a solution to the question.
Until today I could not find a blog post that puts together a good subject about queries with JPA, tips about performance/utilization, source code to download…
Today we will see:
- Model classes and a class that will generate database data
- Find method; Use the getReference method to get a better performance, displaying query parameters in the console with the log4j
- JPQL: Queries with simple parameters or objects, Joins, Order By, Navigating through relationships
- JPQL: Functions: AVG, COUNT, MAX, MIN, TRIM, SUM, UPPER, LOWER, MOD, LENGHT, SQRT; Using HAVING, GROUP BY
- JPQL: Filtering Conditions: LIKE, IN, DISTINCT, EMPTY, BETWEEN, NULL, MEMBER OF, EXISTS (Subqueries), ANY, ALL, SOME, CONCAT, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, LOCATE, SIZE, SUBSTRING
- JPA: NamedQuery, querying with dates, warnings about the getSingleResult method
- JPA: NativeQuery, NamedNativeQuery
- JPA: Complex Native Queries
- JPA: Optimizing queries with EJB
- JPA: Pagination
- JPA: Database Hints
- JPA: Creating a object from a query
- JPQL: Bulk Update and Delete
- JPA: Criteria
You will see that in every main class we will invoke the method “CodeGenerator.generateData()”. This class method only creates data in the database; with this data our queries will find the correct results.
In the last page of this post you will find the link to download the source code of this post.
In this post we will use JPA 2.0 with Hibernate as the provider. The database will be the HSQLDB and will be attached to this project. You can download the source code and run the project without the need of any extra configuration. We will not talk about how to set up the HSQLDB because the focus of this post is how to query data of the database.
This post will not use best practices of development in some points. The focus of this post will be to display how the JPA queries works.
Read the rest of the article at the following URL:
Java Code Geeks : Ultimate JPA Queries and Tips List - Part 1