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

Vaadin JPAContainer

<property name="eclipselink.jdbc.driver" value="org.h2.Driver" />

Database connection is specified with a URL. For example, using an embedded H2 database stored in the home directory it would be as follows:

<property name="eclipselink.jdbc.url" value="jdbc:h2:~/my-app-h2db"/>

A hint: when using an embedded H2 database while developing a Vaadin application in Eclipse, you may want to add ;FILE_LOCK=NO to the URL to avoid locking issues when redeploying.

We can just use the default user name and password for the H2 database:

<property name="eclipselink.jdbc.user" value="sa"/> <property name="eclipselink.jdbc.password" value="sa"/>

Logging Configuration

JPA implementations as well as database engines like to produce logs and they should be configured in the persistence configuration. For example, if using EclipseLink JPA, you can get log that includes all SQL statements with the FINE logging level:

<property name="eclipselink.logging.level" value="FINE" />

Other Settings

The rest is some Data Definition Language settings for EclipseLink. During development, when we use generated example data, we want EclipseLink to drop tables before trying to create them. In production environments, you should use create-tables.

<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />

And there is no need to generate SQL files, just execute them directly to the database.

<property name="eclipselink.ddl-generation.output-mode" value="database"/>

</properties> </persistence-unit>

</persistence>

21.2.6. Troubleshooting

Below are some typical errors that you might get when using JPA. These are not specific to JPAContainer.

javax.persistence.PersistenceException: No Persistence provider for EntityManager The most typical cases for this error are that the persistence unit name is wrong in the source code or in the persistence.xml file, or that the persistence.xml is at a wrong place or has some other problem. Make sure that the persistence unit name matches and the persistence.xml is in WEB-INF/classes/META-INF folder in the deployment.

java.lang.IllegalArgumentException: The class is not an entity

The class is missing from the set of persistent entities. If the persistence.xml does not have exclude-unlisted-classes defined as false, the persistent entity classes should be listed with <class> elements.

Troubleshooting

457

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