You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jpacontainer-installation.asciidoc 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. ---
  2. title: Installing
  3. order: 2
  4. layout: page
  5. ---
  6. [[jpacontainer.installation]]
  7. = Installing
  8. Vaadin JPAContainer can be installed either as an installation package,
  9. downloaded from the Vaadin Directory, or as a Maven dependency. You can also
  10. create a new JPAContainer-enabled Vaadin project using a Maven archetype.
  11. [[jpacontainer.installation.download]]
  12. == Downloading the Package
  13. Vaadin JPAContainer is available for download from the
  14. link:http://vaadin.com/directory[Vaadin Directory]. Please see
  15. <<dummy/../../../framework/addons/addons-downloading#addons.downloading,"Downloading
  16. Add-ons from Vaadin Directory">> for basic instructions for downloading from
  17. Directory. The download page also gives the dependency declaration needed for
  18. retrieving the library with Maven.
  19. JPAContainer is a purely server-side component, so it does not include a widget
  20. set that you would need to compile.
  21. [[jpacontainer.installation.package]]
  22. == Installation Package Content
  23. Once extracted to a local folder, the contents of the installation directory are
  24. as follows:
  25. [filename]#README#:: A readme file describing the package contents.
  26. [filename]#LICENSE#:: The full license text for the library.
  27. [filename]#vaadin-jpacontainer-3.x.x.jar#:: The actual Vaadin JPAContainer library.
  28. [filename]#vaadin-jpacontainer-3.x.x-sources.jar#:: Source JAR for the library. You can use it for example in Eclipse by associating
  29. the JavaDoc JAR with the JPAContainer JAR in the build path settings of your
  30. project.
  31. [filename]#jpacontainer-tutorial.pdf#:: The tutorial in PDF format.
  32. [filename]#jpacontainer-tutorial-html#:: The tutorial in HTML format.
  33. [filename]#jpacontainer-addressbook-demo#:: The JPAContainer AddressBook Demo project covered in this tutorial. You can
  34. compile and package the application as a WAR with " [command]#mvn#
  35. [parameter]#package#" or launch it in the Jetty web browser with "
  36. [command]#mvn# [parameter]#jetty:run#". You can also import the demo project in
  37. Eclipse.
  38. [[jpacontainer.installation.maven]]
  39. == Downloading with Maven
  40. The link:http://vaadin.com/directory[download page in Vaadin Directory] gives
  41. the dependency declaration needed for retrieving the Vaadin JPAContainer library
  42. with Maven.
  43. ----
  44. <dependency>
  45. <groupId>com.vaadin.addon</groupId>
  46. <artifactId>jpacontainer-addon</artifactId>
  47. <version>3.1.0</version>
  48. </dependency>
  49. ----
  50. Use the [literal]#++LATEST++# version tag to automatically download the latest
  51. stable release or use a specific version number as done above.
  52. See <<dummy/../../../framework/addons/addons-maven#addons.maven,"Using Add-ons
  53. in a Maven Project">> for detailed instructions for using a Vaadin add-on with
  54. Maven.
  55. [[jpacontainer.installation.maven.archetype]]
  56. === Using the Maven Archetype
  57. If you wish to create a new JPAContainer-enabled Vaadin project with Maven, you
  58. can use the [literal]#++vaadin-archetype-jpacontainer++# archetype. Please see
  59. <<dummy/../../../framework/getting-started/getting-started-maven#getting-started.maven,"Using
  60. Vaadin with Maven">> for details on creating a Vaadin project with a Maven
  61. archetype.
  62. [[jpacontainer.installation.libraries]]
  63. == Including Libraries in Your Project
  64. The Vaadin JPAContainer JAR must be included in the library folder of the web
  65. application. It is located in [filename]#WEB-INF/lib# path in a web application.
  66. In a normal Eclipse web projects the path is [filename]#WebContent/WEB-INF/lib#.
  67. In Maven projects the JARs are automatically included in the folder, as long as
  68. the dependencies are defined correctly.
  69. You will need the following JARs:
  70. * Vaadin Framework Library
  71. * Vaadin JPAContainer
  72. * Java Persistence API 2.0 (javax.persistence package)
  73. * JPA implementation (EclipseLink, Hibernate, ...)
  74. * Database driver or embedded engine (H2, HSQLDB, MySQL, PostgreSQL, ...)
  75. If you use Eclipse, the Vaadin Framework library is automatically downloaded and
  76. updated by the Vaadin Plugin for Eclipse.
  77. To use bean validation, you need an implementation of the Bean Validation, such
  78. as Hibernate Validator.//TODO
  79. elaborate
  80. [[jpacontainer.installation.configuration]]
  81. == Persistence Configuration
  82. Persistence configuration is done in a [filename]#persistence.xml# file. In a
  83. regular Eclipse project, it should be located in
  84. [filename]#WebContent/WEB-INF/classes/META-INF#. In a Maven project, it should
  85. be in [filename]#src/main/resources/META-INF#. The configuration includes the
  86. following:
  87. * The persistence unit
  88. * The persistence provider
  89. * The database driver and connection
  90. * Logging
  91. The [filename]#persistence.xml# file is packaged as
  92. [filename]#WEB-INF/classes/META-INF/persistence.xml# in the WAR. This is done
  93. automatically in a Maven build at the package phase.
  94. [[jpacontainer.installation.configuration.schema]]
  95. === Persistence XML Schema
  96. The beginning of a [filename]#persistence.xml# file defines the used schema and
  97. namespaces:
  98. ----
  99. <?xml version="1.0" encoding="UTF-8"?>
  100. <persistence
  101. xmlns="http://java.sun.com/xml/ns/persistence"
  102. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  103. xsi:schemaLocation="
  104. http://java.sun.com/xml/ns/persistence
  105. http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  106. version="2.0">
  107. ----
  108. [[jpacontainer.installation.configuration.unit]]
  109. === Defining the Persistence Unit
  110. The root element of the persistence definition is persistence-unit. The name of
  111. the persistence unit is needed for creating [classname]#JPAContainer# instances
  112. from a [classname]#JPAContainerFactory#, as described in
  113. <<dummy/../../../framework/jpacontainer/jpacontainer-usage#jpacontainer.usage.jpacontainerfactory,"Creating
  114. JPAContainer with JPAContainerFactory">> or when creating a JPA entity manager.
  115. ----
  116. <persistence-unit name="addressbook">
  117. ----
  118. Persistence provider is the JPA provider implementation used. For example, the
  119. JPAContainer AddressBook demo uses the EclipseLink JPA, which is defined as
  120. follows:
  121. ----
  122. <provider>
  123. org.eclipse.persistence.jpa.PersistenceProvider
  124. </provider>
  125. ----
  126. The persistent classes need to be listed with a [literal]#++<class>++# element.
  127. Alternatively, you can allow including unlisted classes for persistence by
  128. overriding the [literal]#++exclude-unlisted-classes++# default as follows:
  129. ----
  130. <exclude-unlisted-classes>false</exclude-unlisted-classes>
  131. ----
  132. JPA provider specific parameters are given under the [literal]#++properties++#
  133. element.
  134. ----
  135. <properties>
  136. ...
  137. ----
  138. In the following section we give parameters for the EclipseLink JPA and H2
  139. database used in the JPAContainer AddressBook Demo. Please refer to the
  140. documentation of the JPA provider you use for a complete reference of
  141. parameters.
  142. [[jpacontainer.installation.configuration.database]]
  143. === Database Connection
  144. EclipseLink allows using JDBC for database connection. For example, if we use
  145. the the H2 database, we define its driver here as follows:
  146. ----
  147. <property name="eclipselink.jdbc.platform"
  148. value="org.eclipse.persistence.platform.database.H2Platform"/>
  149. <property name="eclipselink.jdbc.driver"
  150. value="org.h2.Driver" />
  151. ----
  152. Database connection is specified with a URL. For example, using an embedded H2
  153. database stored in the home directory it would be as follows:
  154. ----
  155. <property name="eclipselink.jdbc.url"
  156. value="jdbc:h2:~/my-app-h2db"/>
  157. ----
  158. A hint: when using an embedded H2 database while developing a Vaadin application
  159. in Eclipse, you may want to add [literal]#++;FILE_LOCK=NO++# to the URL to avoid
  160. locking issues when redeploying.
  161. We can just use the default user name and password for the H2 database:
  162. ----
  163. <property name="eclipselink.jdbc.user" value="sa"/>
  164. <property name="eclipselink.jdbc.password" value="sa"/>
  165. ----
  166. [[jpacontainer.installation.configuration.logging]]
  167. === Logging Configuration
  168. JPA implementations as well as database engines like to produce logs and they
  169. should be configured in the persistence configuration. For example, if using
  170. EclipseLink JPA, you can get log that includes all SQL statements with the
  171. [literal]#++FINE++# logging level:
  172. ----
  173. <property name="eclipselink.logging.level"
  174. value="FINE" />
  175. ----
  176. [[jpacontainer.installation.configuration.other]]
  177. === Other Settings
  178. The rest is some Data Definition Language settings for EclipseLink. During
  179. development, when we use generated example data, we want EclipseLink to drop
  180. tables before trying to create them. In production environments, you should use
  181. [literal]#++create-tables++#.
  182. ----
  183. <property name="eclipselink.ddl-generation"
  184. value="drop-and-create-tables" />
  185. ----
  186. And there is no need to generate SQL files, just execute them directly to the
  187. database.
  188. ----
  189. <property name="eclipselink.ddl-generation.output-mode"
  190. value="database"/>
  191. </properties>
  192. </persistence-unit>
  193. </persistence>
  194. ----
  195. [[jpacontainer.installation.troubleshooting]]
  196. == Troubleshooting
  197. Below are some typical errors that you might get when using JPA. These are not
  198. specific to JPAContainer.
  199. [classname]#javax.persistence.PersistenceException#: No Persistence provider for EntityManager:: The most typical cases for this error are that the persistence unit name is
  200. wrong in the source code or in the [filename]#persistence.xml# file, or that the
  201. [filename]#persistence.xml# is at a wrong place or has some other problem. Make
  202. sure that the persistence unit name matches and the [filename]#persistence.xml#
  203. is in [filename]#WEB-INF/classes/META-INF# folder in the deployment.
  204. [classname]#java.lang.IllegalArgumentException#: The class is not an entity:: The class is missing from the set of persistent entities. If the
  205. [filename]#persistence.xml# does not have [parameter]#exclude-unlisted-classes#
  206. defined as [literal]#++false++#, the persistent entity classes should be listed
  207. with [literal]#++<class>++# elements.