How the Criteria API builds dynamic queries and reduces run-time failures
Pinaki Poddar (email@example.com), Senior Software Engineer, IBM
Summary: A query for persistent Java™ objects is typesafe if a compiler can verify it for syntactic correctness. Version 2.0 of the Java Persistence API (JPA) introduces the Criteria API, which brings the power of typesafe queries to Java applications for the first time and provides a mechanism for constructing queries dynamically at run time. This article describes how to write dynamic, typesafe queries using the Criteria API and the closely associated Metamodel API.
As the JPA Expert Group (JSR-317) nears completion of the JPA 2.0 specification, this article introduces you to some of the new concepts and features in this updated specification. It also explains how you can experience this new functionality with the Apache OpenJPA project, an open-source, robust, high performance, scalable implementation of the JPA specification.
The JPA 2.0 Open Alpha has ended and is now included in this Feature Pack Open Beta. Please click the link above to access this new Beta, including code, documentation, and forum support.
Object-relational persistence is a key developer requirement for many application developer scenarios. JPA is the Java EE standard for object-relational persistence and was first introduced as part of Java EE 5. As part of the Java EE 6 standards, JPA 2.0 (JSR-317) updates object-relational capabilities with important developer APIs and enhancements.
Key additions in JPA 2.0 include:
Significant programmer productivity improvements
Innovative APIs from Open Source (standardized)
Extended query language
Welcome to Apache OpenJPA
Apache OpenJPA is a Java persistence project at The Apache Software Foundation that can be used as a stand-alone POJO persistence layer or integrated into any Java EE compliant container and many other lightweight frameworks, such as Tomcat and Spring.
The 1.x releases (1.2.2 is the latest) are a feature-rich, compliant implementation of the Java Persistence API (JPA) 1.0 part of the JSR-220 Enterprise Java Beans 3.0 specification, which pass the Sun JPA 1.0b Technology Compatibility Kit.
The upcoming 2.0 release (see JPA 2.0 Roadmap) implements the JSR-317 Java Persistence 2.0 specification, which is backwards compatible to the JPA 1.0 specification.
With the recent introduction of the Java Persistence API (JPA), WebSphere is forging new trails with their JPA solution. Built on top of the Apache OpenJPA project, the WebSphere JPA solution provides exceptional function, performance, and support. The postings on this site are our own and don’t necessarily represent IBM’s positions, strategies, or opinions.