定义Hibernate实体类与数据库表的关系

定义实体类Applet:

public class Applet extends BaseObject {

	private int ID;
	private String appletType;
	private String appletAid;
	private String cardNo;
	private String applicant;
	private String applyTime;
	private String agreeOrNo;
	private String downloadOrNo;
	private String downloadTime;
	private String deleteOrNo;
	private String deleteTime;
	private String typeName;
	private String appletName;	

	public String getAgreeOrNo() {
		return agreeOrNo;
	}
	public void setAgreeOrNo(String agreeOrNo) {
		this.agreeOrNo = agreeOrNo;
	}
}

 在实体类Applet中,还有很多getter和setter没有写出来。被继承的BaseObject的代码如下

public class BaseObject implements Serializable {

	static final long serialVersionUID = 1;
}

 
在Applet.hbm.xml文件中定义实体类Applet与数据库表TB_APPLET的对应关系:

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

<hibernate-mapping>
 <class name="com.pervcom.mobileota.model.Applet" table="TB_APPLET">  
  <id column="ID" name="ID" unsaved-value="0"> 
      <generator class="native"/>    
   </id>
  <property column="APPLET_TYPE" name="appletType" not-null="false"/>
  <property column="APPLET_AID" name="appletAid" not-null="false"/>  
  <property column="CARD_NO" name="cardNo" not-null="false"/>   
  <property column="APPLICANT" name="applicant" not-null="false"/>  
  <property column="APPLY_TIME" name="applyTime" not-null="false"/>   
  <property column="AGREE_OR_NO" name="agreeOrNo" not-null="false"/>
  <property column="DOWNLOAD_OR_NO" name="downloadOrNo" not-null="false"/>  
  <property column="DOWNLOAD_TIME" name="downloadTime" not-null="false"/>   
  <property column="DELETE_OR_NO" name="deleteOrNo" not-null="false"/>  
  <property column="DELETE_TIME" name="deleteTime" not-null="false"/>
  <property column="TYPE_NAME" name="typeName" not-null="false"/>
  <property column="APPLET_NAME" name="appletName" not-null="false"/>
 </class> 
 </hibernate-mapping>

  在.hbm.xml文件中,元素id定义的是主键的对应关系:

<id column="ID" name="ID" unsaved-value="0"> 
      <generator class="native"/>    
</id>

实体类对应表的建表语句如下:

CREATE TABLE `tb_applet` (
  `ID` int(20) NOT NULL auto_increment,
  `APPLET_TYPE` varchar(20) default NULL,
  `TYPE_NAME` varchar(20) default NULL,
  `APPLET_NAME` varchar(20) default NULL,
  `APPLET_AID` varchar(20) default NULL,
  `CARD_NO` varchar(20) default NULL,
  `APPLICANT` varchar(20) default NULL,
  `APPLY_TIME` varchar(20) default NULL,
  `AGREE_OR_NO` varchar(20) default NULL,
  `DOWNLOAD_OR_NO` varchar(20) default NULL,
  `DOWNLOAD_TIME` varchar(20) default NULL,
  `DELETE_OR_NO` varchar(20) default NULL,
  `DELETE_TIME` varchar(20) default NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

 

你可能感兴趣的:(Hibernate,xml,.net)