Siege Lion on the Way (one) hibernate (eight)---mapping hibernate composition relationship

Source: Internet
Author: User

First, the principle of the use of composition relations :
Minimizing the number of database tables and foreign key references between tables, without causing data redundancy, is a time-consuming operation to establish a connection to multiple tables.
Example: The address attribute in the customer class can be mapped by component, avoiding an additional address table and achieving object-based operations.
Configuration file:

?
1 2 3 4 5 6 7 <component name="homeAddress" class="mypack.Address">   <parent name="customer" />   <property name="province" type="string" column="HOME_PROVINCE"/>   <property name="city" type="string" column="HOME_CITY"/>   <property name="street" type="string" column="HOME_STREET"/>   <property name="zipcode" type="string" column="HOME_ZIPCODE"/> </component>

Description

?
1 2 3 name:设定被映射的持久化类的属性名。 class:设定homeAddress属性的类型。<parent>:指定Address类所属的整体类。

Note: Differentiate whether there are constituent relationships. Hibernate component address has no OID.
1. differentiate between value types and entity types :
Hibernate component address does not have an OID, so you cannot save, update, delete, or load an address object individually through the session. When you use the following methods:

?
1 2 3 4 session.load (Address. class new long ( 1 session.save (address); session.update (address); session.delete (address);

The

throws Org.hibernate.MappingException:Unknow entity class:xx.xxx.Address. The
value type has no OID and cannot be persisted independently, and its life cycle depends on the life cycle of the object that owns the persisted class.  
Two, map composite composition Relationship :
A hibernate component can contain other hibernate components and get other entity class associations. The
configuration file is just the same as the one component nested in component.
Three,

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.