The starting point for making a JavaScript data model is an association-free information
design model where reference properties represent associations. The following model for our
example app contains the multi-valued reference property Book::authors, which
represents the unidirectional many-to-many association Book-has-Author:
This model contains, in addition to the unidirectional many-to-one association Book-has-Publisher, the unidirectional many-to-many association Book-has-Author,
which corresponds to the multi-valued reference property Book::authors.
The meaning of the design model and its reference properties publisher and
authors can be illustrated by a sample data population for the three model
classes:
Table 13.1. Sample data for Publisher
| Name | Address |
|---|---|
| Bantam Books | New York, USA |
| Basic Books | New York, USA |
Table 13.2. Sample data for Book
| ISBN | Title | Year | Authors | Publisher |
|---|---|---|---|---|
| 0553345842 | The Mind's I | 1982 | 1, 2 | Bantam Books |
| 1463794762 | The Critique of Pure Reason | 2011 | 3 | |
| 1928565379 | The Critique of Practical Reason | 2009 | 3 | |
| 0465030793 | I Am A Strange Loop | 2000 | 2 | Basic Books |
Table 13.3. Sample data for Author
| Author ID | Name |
|---|---|
| 1 | Daniel Dennett |
| 2 | Douglas Hofstadter |
| 3 | Immanuel Kant |
We obtain the JPA entity class Author from the corresponding information design
class, as explained in the previous parts of this tutorial, by (1) replacing the stereotype
«stdid» with the property modifier {id}, (2) making all properties private, (3) using Java
datatypes, (4) adding public getters and setters, (5) adding a toString function,
(6) adding the data storage methods add, retrieve, update
and destroy, as well as the helper methods clearData and
createTestData:
In the JPA entity class model, for any dot on a non-functional association end in the design
model, such as the dot on the Author association end in the class diagram above, we
show the reference property representing the association end and annotate it with the
functionality type of the unidirectional association represented by it. In our example, we add a
reference property authors in the entity class Book and annotate it
with the association's functionality type manyToMany: