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

Vaadin JPAContainer

21.2.3. Downloading with Maven

The download page in Vaadin Directory [http://vaadin.com/directory] gives the dependency declaration needed for retrieving the Vaadin JPAContainer library with Maven.

<dependency>

<groupId>com.vaadin.addon</groupId> <artifactId>jpacontainer-addon</artifactId> <version>2.0.0</version>

</dependency>

Use the LATEST version tag to automatically download the latest stable release or use a specific version number as done above.

See Section 17.4, “Using Add-ons in a Maven Project” for detailed instructions for using a Vaadin add-on with Maven.

Using the Maven Archetype

If you wish to create a new JPAContainer-enabled Vaadin project with Maven, you can use the vaadin-archetype-jpacontainer archetype. Please see Section 2.6, “Using Vaadin with Maven” for details on creating a Vaadin project with a Maven archetype.

21.2.4. Including Libraries in Your Project

The Vaadin JPAContainer JAR must be included in the library folder of the web application. It is located in WEB-INF/lib path in a web application. In a normal Eclipse web projects the path is WebContent/WEB-INF/lib. In Maven projects the JARs are automatically included in the folder, as long as the dependencies are defined correctly.

You will need the following JARs:

Vaadin Framework Library

Vaadin JPAContainer

Java Persistence API 2.0 (javax.persistence package)

JPA implementation (EclipseLink, Hibernate, ...)

Database driver or embedded engine (H2, HSQLDB, MySQL, PostgreSQL, ...)

If you use Eclipse, the Vaadin Framework library is automatically downloaded and updated by the Vaadin Plugin for Eclipse.

To use bean validation, you need an implementation of the Bean Validation, such as Hibernate Validator.

21.2.5. Persistence Configuration

Persistence configuration is done in a persistence.xml file. In a regular Eclipse project, it should be located in WebContent/WEB-INF/classes/META-INF. In a Maven project, it should be in src/main/resources/META-INF. The configuration includes the following:

• The persistence unit

Downloading with Maven

455

Vaadin JPAContainer

The persistence provider

The database driver and connection

Logging

The persistence.xml file is packaged as WEB-INF/classes/META-INF/persistence.xml in the WAR. This is done automatically in a Maven build at the package phase.

Persistence XML Schema

The beginning of a persistence.xml file defines the used schema and namespaces:

<?xml version="1.0" encoding="UTF-8"?> <persistence

xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

version="2.0">

Defining the Persistence Unit

The root element of the persistence definition is persistence-unit. The name of the persistence unit is needed for creating JPAContainer instances from a JPAContainerFactory, as described in Section 21.4.1, “Creating JPAContainer with JPAContainerFactory” or when creating a JPA entity manager.

<persistence-unit name="addressbook">

Persistence provider is the JPA provider implementation used. For example, the JPAContainer AddressBook demo uses the EclipseLink JPA, which is defined as follows:

<provider>

org.eclipse.persistence.jpa.PersistenceProvider

</provider>

The persistent classes need to be listed with a <class> element. Alternatively, you can allow including unlisted classes for persistence by overriding the exclude-unlisted-classes default as follows:

<exclude-unlisted-classes>false</exclude-unlisted-classes>

JPA provider specific parameters are given under the properties element.

<properties>

...

In the following section we give parameters for the EclipseLink JPA and H2 database used in the JPAContainer AddressBook Demo. Please refer to the documentation of the JPA provider you use for a complete reference of parameters.

Database Connection

EclipseLink allows using JDBC for database connection. For example, if we use the the H2 database, we define its driver here as follows:

<property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.H2Platform"/>

456

Persistence Configuration

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