How to define named queries at runtime with JPA 2.1
| |

How to define named queries at runtime with JPA 2.1

Defining a static named query via the @NamedQuery annotation is the most common way in JPA. It has the main advantage that the persistence provider can compile and validate the query at start-up time. But you also have to define the query statically at compile time. OK, you can still define a dynamic query at runtime but how do you…

Create type-safe queries with the JPA static metamodel
|

Create type-safe queries with the JPA static metamodel

When you write a criteria query or create a dynamic entity graph, you need to reference the entity classes and their attributes. The quickest and easiest way is to provide the required names as Strings. But this has several drawbacks, e.g. you have to remember or look-up all the names of the entity attributes when you write the query….

How to call stored procedures in JPA – Part 2
| | |

How to call stored procedures in JPA – Part 2

Up to Version 2.1, JPA was missing real support for stored procedures. The only available option was to use a native query. This changed with JPA 2.1, when @NamedStoredProcedureQuery and StoredProcedureQuery were introduced as two of the new features. I wrote about @NamedStoredProcedureQuery and how to use it to define stored procedure calls in the…