首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

联结主键做外键

2012-10-06 
联合主键做外键一.创建PK类import java.io.Serializablepublic class PKCode implements Serializable {p

联合主键做外键

一.创建PK类

import java.io.Serializable;public class PKCode implements Serializable {        private Integer code;        private Integer codeType;        public Integer getCode() {        return code;    }        public void setCode(Integer code) {        this.code = code;    }        public Integer getCodeType() {        return codeType;    }        public void setCodeType(Integer codeType) {        this.codeType = codeType;    }        public boolean equals(Object obj) {        return super.equals(obj);    }        public int hashCode() {        return super.hashCode();    }}

?二.创建实体

public class Code extends MainEntity {        private PKCode codePk;        private String name;        public PKCode getCodePk() {        return codePk;    }        public void setCodePk(PKCode codePk) {        this.codePk = codePk;    }        public String getName() {        return name;    }        public void setName(String name) {        this.name = name;    }}
?
public class CodeType extends MainEntity {        private String name;        public String getName() {        return name;    }        public void setName(String name) {        this.name = name;    }}

?三.创建映射文件

<?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"><!--CODE表 --><hibernate-mapping package="org.apache.dream.common.entity"><class name="Code" table="T_CODE"><composite-id name="codePk"><key-property name="code" column="I_CODE_ID" /><key-property name="codeType" column="I_CODE_TYPE_ID" /></composite-id></class></hibernate-mapping>

?四.联合主键做外键

<!-- 状态 --><many-to-one name="status" /><column name="I_STATUS_CODE_TYPE_ID" /></many-to-one>
?

热点排行