JavaBeat

  • Home
  • 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)
  • Privacy
  • Contact Us

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.

[code lang=”java”]
@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
);
}
}
[/code]

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

Filed Under: Java EE Tagged With: 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.

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.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved