Kodo EJB: Implementing association Relationships between classes and classes

Source: Internet
Author: User

In addition to the inheritance relationship between objects and objects, there is also an association: including a pair of more than one or one pairs of many pairs of one and many pairs, because these relationships in the Kodo EJB implementation of the principle is basically similar, so this article mainly on a pair of related relations in depth, At the same time, through simple examples of analysis and practice in detail how to use the annotations provided in the Kodo EJB to define the association between classes and classes, the remaining One-to-many, Many-to-many and Many-to-many three relationships will only be explained at the end of the article, please refer to the implementation process of one-to-one relationship.

In an object-oriented world, a one-to-one relationship between Class A and Class B must meet the following criteria:

Object A1 references an object B1

Class A other object an cannot apply the same object B1

In a relational database, we typically use a unique foreign key to achieve one-to-one relationships, as illustrated in the following illustration.

Let's begin by introducing the knowledge associated with Kodo EJB and one-to-one relationship implementation, and to illustrate the need, we first define a virtual scene.

Simulation scene

We assume that to complete a library management system, the system needs to manage a lot of books, we need to record the basic information such as the number of books, titles, publication dates and other basic information, but also need to record the preface, order and other information.

Suppose we design the book as a Class (book) according to the above requirements, including the number and name of the books, two attributes, and design the preface information of the book into another Class (Bookextend), which includes the number of the book and two attributes of the preface information. Since a book has a preface and it is impossible to have other books the preface will be the same as him, so the book and the Bookextend naturally form a one-to-one relationship. The properties of these two classes, as well as the relationships between classes, are shown in the following illustration.

Note

1, in order to illustrate the simple, example design, each object only select the necessary attributes.

2, the above design only for the demonstration of the requirements and deliberately adopted, does not represent a reasonable design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.