Unidirectional N: 1 middle table ing

Source: Internet
Author: User

In fact, there is no need to map intermediate tables in part of the time, it seems a lot more, but hibernate also supports this operation, the specific one-way N: 1. If no intermediate table ing exists, refer to mappings.

Now only the changed parts are posted.

 <?  XML version = "1.0" encoding = "UTF-8"  ?>  <!  Doctype hibernate-mapping public "-// hibernate/hibernate mapping DTD 3.0 //" http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"  >  <  Hibernate-Mapping  >      < Class  Name  = "Com. longtech. hibernate. domain. Employee"  Table  = "Employee"  >           <  ID  Name  = "ID"  Column  = "ID"  Type  = "Java. Lang. Long"   >              < Meta  Attribute  = "Field-description"  > Unique Identifier </  Meta  >              <  Generator  Class  = "Native"  />          </  ID  >          <  Property Name  = "Name"  Type  = "Java. Lang. String"  Column  = "Name"  Length  = "20"  >              <  Meta  Attribute  = "Field-description"  > Employee name </  Meta >          </  Property  >          <! --  <Role-to-one name = "department" column = "dept_id" cascade = "all"> </role-to-one>  -->          <  Join  Table  = "Maid"  >              <  Key  Column  = "Empid" > </  Key  >              <  Allow-to-one  Name  = "Department"  Cascade  = "All"  Column  = "Deptid"  > </  Allow-to-one  >          </  Join  >     </  Class  >  </  Hibernate-Mapping  > 

The changed part adds a join label. When using join, an intermediate table is usually specified.

At the database level, it will have an additional intermediate table

empid deptid
1 1

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.