Hibernate and JPA Object relation mapping: relational mapping strategy

Source: Internet
Author: User

Association relationship Mapping

The correlation mapping is a complex mapping relationship in the mapping relationship, which has a pair of more than one or one pairs and many pairs of relationships. They are subdivided into one-way and two-way points. Let's introduce each of the following.

One-way Onetoone

One-way one-to-one is the simplest of the relational mappings, simply that you can query the other party from the associated side, but not the reverse. We use the example below to illustrate that the person entity class in Listing 1 and the address class in Listing 2 are one-way one-to-one relationships where we can query the content of a person's corresponding address, but we can't query the value of an address The person that corresponds to the value.

Listing 1. Owning side of one-way one-to-one relationship

@Entity public
 class person implements Serializable { 
    private static final long serialversionuid = 1L; 
    @Id
    @GeneratedValue (strategy = generationtype.auto) 
    private Long Id; 
    private String name; 
    private int age; 
    @OneToOne
 private address address; 
    
 Getters & Setters 
 }

Listing 2. The opposite end of one-way one-to-one relationship

@Entity public
class address implements Serializable { 
   private static final long serialversionuid = 1L; 
   @Id
   @GeneratedValue (strategy = generationtype.auto) 
   private Long Id; 
   Private String Street; 
   Private String city; 
Private String country; 
gettes& Setters 
}

Figure 1. ER diagram of one-way one-to-one relationship

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.