Table of Contents
This chapter describes the use of the Vaadin JPAContainer add-on.
Vaadin JPAContainer add-on makes it possible to bind user interface components
to a database easily using the Java Persistence API (JPA). It is an
implementation of the Container
interface
described in Section 9.4, “Collecting Items in Containers”.
It supports a typical three-layer application
architecture with an intermediate domain model between
the user interface and the data access layer.
The role of Java Persistence API is to handle persisting the domain model in the database. The database is typically a relational database. Vaadin JPAContainer binds the user interface components to the domain model and handles database access with JPA transparently.
JPA is really just an API definition and has many alternative implementations. Vaadin JPAContainer supports especially EclipseLink, which is the reference implementation of JPA, and Hibernate. Any other compliant implementation should work just as well. The architecture of an application using JPAContainer is shown in Figure 18.2, “JPAContainer Architecture”.
Vaadin JPAContainer also plays together with the Vaadin Bean Validation add-on, which brings Java Bean Validation (JSR 303) to Vaadin applications.
Java Persistence API (JPA) is an API for object-relational mapping (ORM) of Java objects to a relational database. In JPA and entity-relationship modeling in general, a Java class is considered an entity. Class (or entity) instances correspond with a row in a database table and member variables of a class with columns. Entities can also have relationships with other entities.
The object-relational mapping is illustrated in Figure 18.3, “Object-Relational Mapping” with two entities with a one-to-many relationship.
The entity relationships are declared with metadata. With Vaadin JPAContainer, you provide the metadata with annotations in the entity classes. The JPA implementation uses reflection to read the annotations and defines a database model automatically from the class definitions. Definition of the domain model and the annotations are described in Section 18.3.1, “Persistence Metadata”.
The main interface in JPA is the
EntityManager
, which allows making
different kinds of queries either with the Java Persistence Query Language
(JPQL), native SQL, or the Criteria API in JPA 2.0. You can always use the
interface directly as well, using Vaadin JPAContainer only for binding the
data to the user interface.
Vaadin JPAContainer supports JPA 2.0 (JSR 317).
The JPAContainer
is an implementation of the Vaadin
Container
interface that you can bind to
user interface components such as Table
,
Select
, etc.
The data access to the persistent entities is handled with a
entity provider, as defined in the
EntityProvider
interface. JPAContainer
provides a number of different entity providers for different use cases
and optimizations. The built-in providers are described in Section 18.5, “Entity Providers”.