7, unidirectional one-to-many relationship (1 of the party has N of the party's set properties, N is not a side of the 1 of the reference)

Source: Internet
Author: User

One-to-many association relationship

Correlation characteristics: 1 of the party has n the one side of the collection attribute, N of the party does not have 1 of the side of the reference

For example, if the customer has a one-to-many association with order, the customer has an order collection attribute, and the order does not have a reference to the customer. This allows the customer to retrieve all of their order information, but is not able to get the customer to whom the order belongs.

There are two key points to mapping a one-to-many association relationship:

1, using @onetomany annotations for one-way-to-many mappings;

2, using @joincolumn to map the name of the foreign key column;

Note the point:

1. The default retrieval policy for @OneToMany is a deferred load policy, which can be modified to retrieve the policy immediately by setting its property fetch=fetchtype.eager;

2. A one-way-to-many association set by @OneToMany can delete 1 of the party by default.

Processing: First set all foreign keys of its associated n data table to NULL, and then delete the 1 side.

You can set the @onetomany property Cascade={cascadetype.remove} to cascade Delete (delete the 1 side and delete the same side simultaneously, you can also set the other delete policy )

7, unidirectional one-to-many relationship (1 of the party has N of the party's set properties, N is not a side of the 1 of the reference)

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.