JPA object link ing

Source: Internet
Author: User

Onetoone

 

 
Public classemployee implements serializable {...... @ Onetoone (cascade = cascadetype. All, orphanremoval = true, fetch = fetchtype. Lazy) @ joincolumn (name = "addr_id") Private Address ;... ...}

 

 

Manytoone

 

 
Public classemployee implements serializable {...... @ Manytoone (fetch = fetchtype. lazy) @ jointable (name = "emp_job", joincolumns = @ joincolumn (name = "emp_id"), inversejoincolumns = @ joincolumn (name = "title_id ")) // keys are connected to the primary keys column of the table joincolumns primary test master table, the inversejoincolumns primary test field, or the private jobtitle column of the primary keys column of the table generated by attention; @ manytoone (fetch = fetchtype. lazy) @ joincolumn (name = "manager_id") private employee manager ;... ...}

 

 

Onetoworkflow

 

 
Public classemployee implements serializable {...... @ Onetomany (mappedby = "manager") // The manager field private list <employee> managedemployees = newarraylist <employee> (); @ onetomany (mappedby = "owner ", cascade = cascadetype. all, orphanremoval = true) Private list <phonenumber> phonenumbers = newarraylist <phonenumber> (); @ onetoworkflow (cascade = cascadetype. all, orphanremoval = true) @ joincolumn (name = "emp_id") Private list <degree> degrees = newarraylist <de Gree> ();......}

 

 

Manytoyun

Public classemployee implements serializable {...... @ Manytomany // @ jointable (name = "proj_emp", joincolumns = @ joincolumn (name = "emp_id"), inversejoincolumns = @ joincolumn (name = "proj_id ")) private list <project> projects = newarraylist <project> ();... ...}

 

 

Joint primary key ing

Manytoone onetow.manytoyun ing, And the jointable ing will show the joint primary key, that is, the double primary key.

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.