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-overview.asciidoc 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. title: Overview
  3. order: 1
  4. layout: page
  5. ---
  6. [[jpacontainer.overview]]
  7. = Overview
  8. NOTE: Using JPAContainer is no longer recommended.
  9. While it works for simple data models, it is not as easy to use as it should be.
  10. It also has architectural weaknesses and performance issues that cause problems in building more complex applications.
  11. Instead, we recommend using JPA directly, while hiding it from your UI logic behind a DAO or service class.
  12. In UI code, you should mainly handle beans and collections of beans, bound to a [classname]#BeanItemContainer#. You should also note the https://vaadin.com/directory#!addon/viritin[Viritin] add-on, which provides data binding features that help with JPA.
  13. Vaadin JPAContainer add-on makes it possible to bind user interface components
  14. to a database easily using the Java Persistence API (JPA). It is an
  15. implementation of the [interfacename]#Container# interface described in
  16. <<dummy/../../../framework/datamodel/datamodel-container#datamodel.container,"Collecting
  17. Items in Containers">>. It supports a typical three-layer application
  18. architecture with an intermediate __domain model__ between the user interface
  19. and the data access layer.
  20. [[figure.jpacontainer.overview.architecture]]
  21. .Three-Layer Architecture Using JPAContainer And JPA
  22. image::img/three-layer-architecture-hi.png[]
  23. The role of Java Persistence API is to handle persisting the domain model in the
  24. database. The database is typically a relational database. Vaadin JPAContainer
  25. binds the user interface components to the domain model and handles database
  26. access with JPA transparently.
  27. JPA is really just an API definition and has many alternative implementations.
  28. Vaadin JPAContainer supports especially EclipseLink, which is the reference
  29. implementation of JPA, and Hibernate. Any other compliant implementation should
  30. work just as well. The architecture of an application using JPAContainer is
  31. shown in <<figure.jpacontainer.overview.detailed-architecture>>.
  32. [[figure.jpacontainer.overview.detailed-architecture]]
  33. .JPAContainer Architecture
  34. image::img/detailed-architecture-hi.png[]
  35. Vaadin JPAContainer also plays together with the Vaadin support for Java Bean
  36. Validation (JSR 303).
  37. [[jpacontainer.overview.jpa]]
  38. == Java Persistence API
  39. Java Persistence API (JPA) is an API for object-relational mapping (ORM) of Java
  40. objects to a relational database. In JPA and entity-relationship modeling in
  41. general, a Java class is considered an __entity__. Class (or entity) instances
  42. correspond with a row in a database table and member variables of a class with
  43. columns. Entities can also have relationships with other entities.
  44. The object-relational mapping is illustrated in
  45. <<figure.jpacontainer.overview.jpa.orm>> with two entities with a one-to-many
  46. relationship.
  47. [[figure.jpacontainer.overview.jpa.orm]]
  48. .Object-Relational Mapping
  49. image::img/jpa-mapping-graphic-hi.png[]
  50. The entity relationships are declared with metadata. With Vaadin JPAContainer,
  51. you provide the metadata with annotations in the entity classes. The JPA
  52. implementation uses reflection to read the annotations and defines a database
  53. model automatically from the class definitions. Definition of the domain model
  54. and the annotations are described in
  55. <<dummy/../../../framework/jpacontainer/jpacontainer-domain-model#jpacontainer.domain-model.annotation,"Persistence
  56. Metadata">>.
  57. The main interface in JPA is the [interfacename]#EntityManager#, which allows
  58. making different kinds of queries either with the Java Persistence Query
  59. Language (JPQL), native SQL, or the Criteria API in JPA 2.0. You can always use
  60. the interface directly as well, using Vaadin JPAContainer only for binding the
  61. data to the user interface.
  62. Vaadin JPAContainer supports JPA 2.0 (JSR 317). It is available under the Apache
  63. License 2.0.
  64. [[jpacontainer.overview.concepts]]
  65. == JPAContainer Concepts
  66. The [classname]#JPAContainer# is an implementation of the Vaadin
  67. [interfacename]#Container# interface that you can bind to user interface
  68. components such as [classname]#Table#, [classname]#ComboBox#, etc.
  69. The data access to the persistent entities is handled with a __entity
  70. provider__, as defined in the [interfacename]#EntityProvider# interface.
  71. JPAContainer provides a number of different entity providers for different use
  72. cases and optimizations. The built-in providers are described in
  73. <<dummy/../../../framework/jpacontainer/jpacontainer-entityprovider#jpacontainer.entityprovider,"Entity
  74. Providers">>.
  75. [classname]#JPAContainer# is by default __unbuffered__, so that any entity
  76. property changes are written immediately to the database when you call
  77. [methodname]#setValue()# for a property, or when a user edits a bound field. A
  78. container can be set as __buffered__, so that changes are written on calling
  79. [methodname]#commit()#. Buffering can be done both at item level, such as when
  80. updating item property values, or at container level, such as when adding or
  81. deleting items. Only __batchable__ containers, that is, containers with a
  82. batchable entity provider, can be buffered. Note that buffering is recommended
  83. for situations where two users could update the same entity simultaneously, and
  84. when this would be a problem. In an unbuffered container, the entity is
  85. refreshed before writing an update, so the last write wins and a conflicting
  86. simultaneous update written before it is lost. A buffered container throws an
  87. [classname]#OptimisticLockException# when two users edit the same item (an
  88. unbuffered container never throws it), thereby allowing to handle the situation
  89. with application logic.
  90. [[jpacontainer.overview.documentation]]
  91. == Documentation and Support
  92. In addition to this chapter in the book, the installation package includes the
  93. following documentation about JPAContainer:
  94. * API Documentation
  95. * JPAContainer Tutorial
  96. * JPAContainer AddressBook Demo
  97. * JPAContainer Demo