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

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