How to call custom database functions with JPA and Hibernate
| |

How to call custom database functions with JPA and Hibernate

JPA supports a set of database functions which you can use to perform small operations and transformations within a query. This is often easier and faster than doing it in the Java code. But how do you call functions which are not supported by the JPA standard, like database-specific ones or the custom functions implemented…

| | |

Free Mini Course: How to find and fix n+1 select issues with Hibernate

Loading related entities with JPA and Hibernate is a comfortable feature that is also the most common reason for performance issues. In most applications you can find one of these two issues: related entities are eagerly loaded, even if they are not needed or related entities are lazily loaded which creates n+1 select issues if…

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…