2. Make a JPA Entity Class Model

The starting point for making a JavaScript data model is an association-free information design model like the following one:

Notice the unidirectional many-to-one association between Book and Publisher, assigning at most one publisher to any book, which is represented by the reference property publisher in the Book class.

The meaning of the design model can be illustrated by a sample data population for the two model classes Book and Publisher:

Table 12.1. Sample data for Publisher

Name Address
Bantam Books New York, USA
Basic Books New York, USA

Table 12.2. Sample data for Book

ISBN Title Year Publisher
0553345842 The Mind's I 1982 Bantam Books
1463794762 The Critique of Pure Reason 2011
1928565379 The Critique of Practical Reason 2009
0465030793 I Am A Strange Loop 2000 Basic Books

We obtain the JPA entity class Publisher 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 association end dot in the design model, 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 publisher in the entity class Book and annotate it with the association's functionality type manyToOne: