JPA 2.1 New Features

JPA 2.1 adds lot of enhancements on top of the JPA 2.0 features. Some of the notable features are custom converters, criteria update, stored procedures, DDL generation, entity groups, etc. Here I have listed all the changes and explained few of the features. I will write examples for each features in the future articles.

1. Converters

One of the common problem with storing the values to the database is converting the matching data type from Java object to the database table. If the Java type has the boolean, the corresponding database values could be either ‘0’ or ‘1’. The desired conversion could not happen automatically without the explicit handling of the conversion. JPA 2.1 introduces the new annotations @Converter, @Convert and <converter>, <convert> elements. Converter is a custom converter class implements the interface AttributeConverter and annotated with the @Converter. It defines the conversion types.

public class BooleanConverter implements AttributeConverter<Boolean, String>{
    public String convertToDatabaseValue(Boolean indicator) {
        if (indicator) {
            return "1";
        } else {
            return "0";
    public Boolean convertToEntityAttribute(String indicator) {
        return "1".equals(indicator

2. CriteriaUpdate

CriteriaUpdate is database update query. CriteriaUpdate defines the following clauses and options.

  • set(String, Object), set(Path, Object), set(Path, Expression) – Defines the update’s set clause.
  • where(Expression)where(Predicate...) – Defines the update’s where clause. By default all instances of the class are updated.

3. Stored Procedures

JPA 2.1 supports the calling of stored procedures by using the  StoredProcedureQuery or @NamedStoredProcedureQuery annotation.

4. ConstructorResult

5. Runtime creation of named queries

6. Injectable EntityListeners

7. Unsynchronized persistence contexts

8. DDL generation – automatic table, index and schema generation.

9. Entity Graphs – allow partial or specified fetching or merging of objects.

10. JPQL/Criteria enhancements

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!