Unsynchronized PersistenceContext – How to model conversations with JPA
| |

Unsynchronized PersistenceContext – How to model conversations with JPA

Most Java EE applications are stateless and there are good reasons for it. But not all user interactions can be implemented in that way. Sometimes you need to model a conversation that consists of multiple steps, like the typical shopping cart or complex update operations. Doing this with JPA 2.0 always felt a little bit…

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…