One-to-one ing file configuration in hibernate

Source: Internet
Author: User

Data Persistence is inevitable during project development. There are one-to-one, one-to-multiple, multiple-to-one, and multiple-to-multiple centralized models in the relational model. The following describes how these models are implemented in Hibernate and makes a simple record:

The first is a one-to-one model,

In this model, each student has a library card and a library card can only correspond to one student. The library card cannot exist independently. Then student's PK is ID, library_card's PK, and fk id is dependent on student's PK.

The following is a class diagram of the two classes and how to configure their ing files.

Student ing file:

<? XML version = "1.0"?> <! Doctype hibernate-mapping public "-// hibernate/hibernate DTD ing DTD 3.0 // en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">                 <property name="name"></property>

<One-to-one name = "librarycard"> </one-to-one> </class>


Librarycard ing file:

<? XML version = "1.0"?> <! Doctype hibernate-mapping public "-// hibernate/hibernate DTD ing DTD 3.0 // en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<one-to-one name="student"  constrained="true"></one-to-one>

Constrained is used to add a foreign key constraint to the table structure. If it is not added, it will not be affected.

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.