Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Chapter 21

Vaadin

JPAContainer

21.1. Overview ..............................................................................................

451

21.2. Installing ..............................................................................................

453

21.3. Defining a Domain Model ....................................................................

458

21.4. Basic Use of JPAContainer ..................................................................

461

21.5. Entity Providers ...................................................................................

466

21.6. Filtering JPAContainer .......................................................................

469

21.7. Querying with the Criteria API .............................................................

469

21.8. Automatic Form Generation .................................................................

470

21.9. Using JPAContainer with Hibernate .....................................................

473

This chapter describes the use of the Vaadin JPAContainer add-on.

21.1. Overview

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.5, “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.

Book of Vaadin

451

Vaadin JPAContainer

Figure 21.1. Three-Layer Architecture Using JPAContainer And JPA

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 21.2, “JPAContainer Architecture”.

Figure 21.2. JPAContainer Architecture

Vaadin JPAContainer also plays together with the Vaadin support for Java Bean Validation (JSR 303).

Java Persistence API

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 21.3, “Object-Relational Mapping” with two entities with a one-to-many relationship.

452

Java Persistence API

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]