hibernate 自动生成主键,即主键自增长

<?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="com.shjv.tdscdma.epmsgroup.info.domain">
    <!-- 
	    参数
	-->
    <class name="PmsElectronicSignatures" table="pms_electronic_singnature_t" lazy="true">
		<id name="kid" type="java.lang.String">
            <column name="id" length="32" />
            <generator class= "uuid"></generator>
        </id> 
		<property name="updatetime" type="java.sql.Timestamp">
			<column name="updatetime" />
		</property>  
		<property name="url" type="java.lang.String">
			<column name="url" />
		</property>
		<property name="username" type="java.lang.String">
			<column name="username" />
		</property>
		<property name="isgained" type="java.lang.Boolean">
			<column name="isgained" />	
		</property>
    </class> 
</hibernate-mapping>
================================================================================


public class PmsElectronicSignatures extends DomainObject{
	    private static final long serialVersionUID = 6331142274237543842L;
	    private String kid;
	    private String username;
	    private String url;
	    private Date updatetime;
	    private boolean isgained;
	    
	   
		public String getKid() {
			return kid;
		}
		public void setKid(String kid) {
			this.kid = kid;
		}
		public String getUsername() {
			return username;
		}
		public void setUsername(String username) {
			this.username = username;
		}
		public String getUrl() {
			return url;
		}
		public void setUrl(String url) {
			this.url = url;
		}
		public Date getUpdatetime() {
			return updatetime;
		}
		public void setUpdatetime(Date updatetime) {
			this.updatetime = updatetime;
		}
		public boolean isIsgained() {
			return isgained;
		}
		public void setIsgained(boolean isgained) {
			this.isgained = isgained;
		}
		
		 @Override
			public String toString() {
				return "PmsElectronicSignatures [kid=" + kid + ", username="
						+ username + ", url=" + url + ", updatetime=" + updatetime
						+ ", isgained=" + isgained + "]";
			}
		@Override
		public int hashCode() {
			return super.hashCode()*this.kid.hashCode();
		}
		@Override
		public boolean equals(Object object) {
			if(!(object instanceof PmsElectronicSignatures)){
				return false;
			}
			
			PmsElectronicSignatures pmsElectronicSignatures = (PmsElectronicSignatures)object;
			return pmsElectronicSignatures.getKid().compareTo(this.kid)==0 ?true:false;
		}		
}
==================================================================================
drop table if exists pms_electronic_singnature_t;
create table pms_electronic_singnature_t
(
   id                varchar (32) not null primary key,
   username          varchar(255) not null ,
   url               varchar(255) ,
   updatetime         datetime,
   isgained           boolean default false
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

你可能感兴趣的:(Hibernate)