• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JPA 2.1 New Features

December 26, 2013 //  by Krishna Srinivasan//  Leave a Comment

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.

@Converter
public class BooleanConverter implements AttributeConverter<Boolean, String>{
    @Override
    public String convertToDatabaseValue(Boolean indicator) {
        if (indicator) {
            return "1";
        } else {
            return "0";
        }
    }
    @Override
    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

Category: Java EETag: JPA 2 Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « JPA 2.0 New Features
Next Post: JPA 2 MetaModel Generation using Eclipse »

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact