Component mapping
In hibernate, the component map uses <component> tags to
Component is the logical component of an entity, and the main difference between it and the entity class is that it has no OID
Component is called a value class in DDD
The advantages of using component: To realize the fine-grained division of the object model, high reuse rate, clear meaning and distinct hierarchy
Object model and relational model design on the contrary, the object model is generally fine-grained, and the relational model is generally coarse-grained.
Example:
Object Model:
Relational Model:
Map file:
Employee.hbm.xml
[HTML]View Plaincopyprint?
- <hibernate-mapping>
- <class name="Com.jialin.hibernate.Employee" table="T_emplyee">
- <ID name="id">
- <generator class="native"/>
- </ID>
- <property name="name"/>
- <component name="Employeecontact">
- <property name="email"/>
- <property name="Address"/>
- <property name="ZipCode"/>
- <property name="Contacttel"/>
- </Component>
- </class>
- </hibernate-mapping>
User.hbm.xml
[HTML]View Plaincopyprint?
- <hibernate-mapping>
- <class name="Com.jialin.hibernate.User" table="T_user">
- <ID name="id">
- <generator class="native"/>
- </ID>
- <property name="name"/>
- <component name="Usercontact">
- <property name="email"/>
- <property name="Address"/>
- <property name="ZipCode"/>
- <property name="Contacttel"/>
- </Component>
- </class>
- </hibernate-mapping>
An analysis of Hibernate mapping (iv)--component mapping (component)