zoukankan      html  css  js  c++  java
  • 浅析Hibernate映射(四)——组件映射(component)

    Component映射

    在hibernate中Component映射采用<component>标签即可

    Component是某个实体的逻辑组成部分,它与实体类的主要差别在于,它没有oid
    Component在DDD中被称为值类

    采用Component的好处:实现对象模型的细粒度划分,复用率高,含义明确,层次分明

    对象模型与关系模型的设计恰恰相反,对象模型一般是细粒度的,关系模型一般是粗粒度的

    示例:

    对象模型:

    关系模型:

    映射文件:

    Employee.hbm.xml

    <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

    <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>


     

  • 相关阅读:
    Logstash IIS日志采集
    Logstash_Apache日志采集
    k8s 资源管理
    获取hdfs集群信息(fs.defaultFS)
    PHP CMS的pc标签
    流程
    PHP复习
    权限管理
    注册审核
    简单的文件管理程序练习
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3013959.html
Copyright © 2011-2022 走看看