[Hibernate3-Summary] [section 3rd]: Today's summary-joint primary key

Source: Internet
Author: User

[Joint primary key]

>>>> Configuration method: XML:
1. Create a primary key entity class for studentpk separately in student

2. Configuration:

<composite-id name="studentPK">     <key-property name="name" column="username" />     <key-property name="nickname" column="nickname" /> </composite-id>

>>>> Annotation method: Annotation

1. Create a teacherpk primary key entity class separately in teacher
2. Annotation
** Annotation Method 1: [one annotation] ※common

<1>

@EmbeddedIdpublic TeacherPk getTeacherPk()

<2> the primary key class implements the serializable interface + overwrites the hashcode and equals methods.

TeacherPk implements Serializable{    @Override    public int hashCode()    @Override    public boolean equals(Object obj)}

** Annotation Method 2: [two annotations]

<1>

@Embeddablepublic class TeacherPk implements Serializable

@Idpublic TeacherPk getTeacherPk()

<2> same as above

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.