Hibernate mapping relationships: one to one, one to many and many to many

In Hibernate, it may also be present to operate the table association of multiple, but need in the mapping file, the foreign key relationship between the objects associated database table mapping. Association chapter will explain in detail the Hibernate mapping.

In a relational database, there are three tables among multiple relationship, respectively, one to one, one to many and many to many, shown in Figure 1  

           

                                            Three kinds of relationship between a plurality of tables in a relational database in FIG. 1

Detailed description of these three associations are as follows.

  • One: any other one of the primary key is introduced as a foreign key.
  • Many: one of the "many" add "a" of one of the primary key as a foreign key.
  • Many-: generating an intermediate table, the introduction of two primary key table as a foreign key, two primary keys become the primary key.


May describe the relationship between the entity data from database tables, likewise, may be described by an object. In Hibernate, using  Java  relationships between data tables describe the relationship between the entity object, as shown in FIG.

As can be seen from Figure 2, one to one relationship is the definition of the object type in this other class, as defined in the class A type B type B properties, class B, class A type attribute defines a; many relationship, a case where a plurality of categories corresponding to a type of B class type a, needs to be introduced in the manner set set Object class a class B type, a class defines a type attribute in class B; many- relationship, define the class B type set in the set class a, class type definitions set a set of class B, the object set is used here to avoid duplication set data.

These are the relationships between Java objects of three entity classes, as one association not commonly used in development, so the tutorial does not explain alone, as the reader can understand.

                                                           The relationship between FIG. 2 Java object description data table

 

About Hibernate mapping relationship of one to many and many-to-please readers click on the following link to read:

Transfer: http://c.biancheng.net/view/4198.html

 

 

 

 

Guess you like

Origin www.cnblogs.com/halesir88/p/11988362.html