HibernateBean的写法,有单一主键,复合主键

/**
 * @hibernate.class table="pwmip.pwmip_CastChannel"
 */
public class pwmip_CastChannel
{
	private int ASNo;
	 
	private ServerInfo id;
	
	 
    
        public pwmip_CastChannel(){

        }
 

	/**
	 * @hibernate.id class="ServerInfo"
	 */
	
	public ServerInfo getId() {
		return id;
	}




	public void setId(ServerInfo id) {
		if(id!=null)
		{
			if(id.getASNo()!=null)
				this.ASNo=id.getASNo().intValue();
			
			if(id.getCastChannelNo()!=null)
				this.CastChannelNo=id.getCastChannelNo().intValue();
			
			if(id.getServerNo()!=null)
				this.ServerNo=id.getServerNo().intValue();
			
		}
		this.id = id;
	}
	public int getASNo(){
		return this.ASNo;
	}

	public void setASNo(int ASNo){
		if(id==null)
	 
			id=new ServerInfo();
			
		id.setASNo(new Integer(ASNo));
			
		 
		
		this.ASNo=ASNo;
	}

	public int getCastChannelNo(){
		return this.CastChannelNo;
	}

	public void setCastChannelNo(int CastChannelNo){
		
		if(id==null)
			 
			id=new ServerInfo();
			
		id.setCastChannelNo(new Integer(CastChannelNo));
			
		this.CastChannelNo=CastChannelNo;
	}
	
	 public int getServerNo(){
         return this.ServerNo;
	 }
	
	 public void setServerNo(int ServerNo){
		 
		 if(id==null)
			 
				id=new ServerInfo();
				
		id.setServerNo(new Integer(ServerNo));
		
	    this.ServerNo=ServerNo;
	 }

	/**
	 * @hibernate.property  column="CastChannelName"
	 */
	public String getCastChannelName(){
		return this.CastChannelName;
	}

 

}



/**
 * 
 */
  

import java.io.Serializable;

/**
 * @author zhenjw
 *
 */
public class ServerInfo implements Serializable {
	
	 // Fields    

    private Integer ASNo;
    private Integer CastChannelNo;
    private Integer ServerNo;
    
   

   /** default constructor */
   public ServerInfo() {
   }

   
   /** full constructor */
   public ServerInfo(Integer ASNo, Integer CastChannelNo) {
       this.ASNo = ASNo;
       this.CastChannelNo = CastChannelNo;
   }

  
   // Property accessors

   /**
    * @hibernate.property column="ASNo"
    */
   public Integer getASNo() {
       return this.ASNo;
   }
   
   public void setASNo(Integer ASNo) {
       this.ASNo = ASNo;
   }

   /**
    * @hibernate.property column="CastChannelNo"
    * 
    */
   public Integer getCastChannelNo() {
       return this.CastChannelNo;
   }
   
   public void setCastChannelNo(Integer CastChannelNo) {
       this.CastChannelNo = CastChannelNo;
   }
    
   /**
    * @hibernate.property column="ServerNo"
    * 
    */
  public Integer getServerNo() {
	return ServerNo;
}


public void setServerNo(Integer serverNo) {
	ServerNo = serverNo;
}


public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (!super.equals(obj))
		return false;
	if (getClass() != obj.getClass())
		return false;
	final ServerInfo other = (ServerInfo) obj;
	if (ASNo == null) {
		if (other.ASNo != null)
			return false;
	} else if (!ASNo.equals(other.ASNo))
		return false;
	if (CastChannelNo == null) {
		if (other.CastChannelNo != null)
			return false;
	} else if (!CastChannelNo.equals(other.CastChannelNo))
		return false;
	if (ServerNo == null) {
		if (other.ServerNo != null)
			return false;
	} else if (!ServerNo.equals(other.ServerNo))
		return false;
	return true;
}
  
  public int hashCode() {
	final int PRIME = 31;
	int result = super.hashCode();
	result = PRIME * result + ((ASNo == null) ? 0 : ASNo.hashCode());
	result = PRIME * result + ((CastChannelNo == null) ? 0 : CastChannelNo.hashCode());
	result = PRIME * result + ((ServerNo == null) ? 0 : ServerNo.hashCode());
	return result;
}   




}

这只是一个样例,没有时间调了,有时间再进行修改,先备份了。
搬家之后不能上网很郁闷啊!

你可能感兴趣的:(Hibernate)