实体粒度划分

     实体粒度划分顾名思义就是将一个比较大的对象进行拆分,划分为几个小的对象。但是这种粒度的划分只是针对类对象,而不是针对数据表。

 

实体的细粒度划分优点:
1,通过细粒度划分使系统逻辑更加清晰
2,性能方面,能提高系统的能耗比(性能/资源消耗)

 

举例如下:

1,新建表person

create table Person(
  id number(20) primary key,
  firstName varchar2(50) not null,
  lastName varchar2(50) not null,
  telphone varchar2(11) ,
  email varchar2(30),
  zipcode varchar2(30)
)

 2,因为类的属性太多,故可以将person类进行粒度的划分,将属性进行归类。

public class Name {
	
  private String firstName = "";
  
  private String lastName = "";
  
  
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}

 

public class Contact {
  
	private String email = "";
	
	private String telphone = "";
	
	private String zipcode = "";
	

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getTelphone() {
		return telphone;
	}

	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}
}

 将以上两个类作为Person类的属性

public class Person {
  
	private int id ;
	
	private Name name ;
   
	private Contact contact;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Name getName() {
		return name;
	}

	public void setName(Name name) {
		this.name = name;
	}

 3,Person.hbm.xml文件配置如下

 

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="包名">

    <class name="Person" table="Person">
        <id name="id" column="ID" type="int">
            <generator class="sequence">
               <param name="sequence">序列名</param>
            </generator>
        </id>
        <component name="name" class="Name">
           <property name="firstName" column="firstName" type="string"/>
           <property name="lastName" column="lastName" type="string"/>
        </component>
        <component name="contact" class="Contact">
           <property name="email" column="email" type="string"/>
           <property name="telphone" column="telphone" type="string"/>
           <property name="zipcode" column="zipcode" type="string"/>
        </component>
        
    </class>
    
</hibernate-mapping>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值