Hibernate relationship ing

Source: Internet
Author: User
This article is the original blogger, allowed to reprint, but please declare the original address: www.coselding.cnblog88-140.html 1, ing:. one-to-one: Primary Key Association one-way: foreign key Association two-way: foreign key association or intermediate table joint primary key: @ OneToOne: one-to-one association, annotation on the get method referenced by the peer class @ Join

This article is the original blogger, allowed to reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-140.html 1, ing:. one-to-one: Primary Key Association one-way: foreign key Association two-way: foreign key association or intermediate table joint primary key: @ OneToOne: one-to-one association, annotation on the get method referenced by the peer class @ Join

This article is the original blogger, allowed to reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-140.html

1. Link ing:
A. One-to-one: Primary Key Association
Unidirectional: foreign key Association
Bidirectional: foreign key association or intermediate table
Joint primary key:
@ OneToOne: one-to-one association, which is annotated on the get method referenced by the peer class
@ JoinColumn: sets the associated foreign key name and name attribute.
@ PrimaryKeyJoinColumn: Set primary key Association
@ JoinColumns set the joint primary key
Xml usage Label to add the unique attribute.
B. One-to-multiple: Add a Set of multiple parties
Annotation: @ onetoworkflow and @ JoinColumn specify the foreign key names of multiple parties
Xml:
C. Multiple-to-one: Add Foreign keys to multiple parties
Annotation: @ ManyToOne
Xml:
Note: one-to-many and multiple-to-one bidirectional relationships are handed over to multiple parties for maintenance, and mappedBy is set at @ onetoworkflow.
Attribute, xml in Set inverse = "false"
D. many to many:
Unidirectional:
Note: @ manytoable, @ JoinTable specifies the middle table name and column name on the maintenance set,
JoinColumns, JoinColumn, inverseJoinColumn
Xml:
Bidirectional:
Annotation: Set @ ManyToMany (mappedBy = "") on the other side of the Set Based on One-Way "")
Xml: the other side is also set Tag
E. Component ing: beans that are part of a table are not used as entities, such as student IDs as part of student entities;
Add @ Embedded
Used in Xml Tag
Note: (1) the edby attribute must be set for Bidirectional Association. Property-ref attribute
Indicates that the link is dominated by the other party;
(2) Two-way relationships should pay attention to the possibility of stack overflow of entity infinite loop calls during the call process;
2. add, delete, modify, and query under the association:
(1) cascade operations of association relationship settings only affect addition, deletion, and modification;
(2) If the associated object is one party, the EAGER is retrieved by default;
(3) If the associated object is multiple parties, the default value is delayed loading and LAZY;
(4) fetch: sets query and read cascade operations, which only affects query operations. The default value is LAZY;
(5) two-way Association operations may lead to repeated operations. Pay attention to setting delayed loading to avoid unnecessary operations;
(6) Delete: first query and then delete to prevent cascading deletion-damage the association relationship of memory entities or HQL;
3. Set ing:
(1) conventional method: Set;
(2) List: Add annotation and Set. List is to be able to sort. @ OrderBy specifies the sorting parameter;
(3) Map: The key is a non-repeated child segment (most of which is a primary key), @ MapKey; value is a set element entity, and is more suitable for queries;
4. Inheritance ing:
(1) inheritance relationship of a few attributes: Single-Table. A Table stores all classes and adds a type to mark the seat segment;
(2) Each Class has its own Table: Table-per-Class. It cannot store the inherited polymorphism. It is difficult to inherit the polymorphism, and the uniqueness of each entity's primary key must be maintained;
(3) According to the inheritance relationship, the parent class has tables and sub-classes also have tables, but the common attributes are in the parent table: Joined. The parent and sub-tables must set primary key associations to maintain primary key uniqueness, the query must be connected to the table. The new subclass must create a new table;
Annotation: A. @ Inheritance: Specify the Inheritance ing and specify the Inheritance ing policy for the parent class;
B. @ DiscriminatorColumn: indicates the type flag bits of the class for the parent class;
C. @ DiscriminatorValue ("tag bit value"): class type tag bit value;
5. Tree map:
(1) Object Design: id, Father's Day point reference, child node set, and other node content;
(2) Table Design: id, parent_id, and other node content columns;
(3) set @ Entity, @ Id, primary key generation policy, @ ManyToOne (set the foreign key column "parent_id"), and @ onetoworkflow (mappedBy = "parent ");
(4) set and modify the cascade. Select LAZY or EAGER for specific analysis;
(5) set the parent-child relationship between objects and store them in the database;
(6) recursive queries are used for queries;

This article is the original blogger, allowed to reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-140.html

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.