product.java

来自「jboss4 + Mysql +ejb3.0 EJB3 简单例子」· Java 代码 · 共 81 行

JAVA
81
字号
/**
 * Copyright (c)上海烟草(集团)公司与上海康时信息系统有限公司。
 */
package com.myejb.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 事务实例用到的Entity
 * @author xywang
 * @since 2009-2-25
 * @version 1.0
 */
@SuppressWarnings("serial")
@Entity
@Table(name="Products")
public class Product implements Serializable{
    private int hashCode = Integer.MIN_VALUE;
    private Integer productid;
    private String name;
    private Float price;
    public Product(){}
    public Product(String name,Float price){
        this.name = name;
        this.price= price;
    }
    @Column(name="ProductName",nullable=false,length=50)
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    @Column(nullable=false)
    public Float getPrice(){
        return price;
    }
    public void setPrice(Float price){
        this.price = price;
    }
    @Id
    @GeneratedValue
    public Integer getProductid(){
        return productid;
    }
    public void setProductid(Integer productid){
        this.productid = productid;
    }
    public int hashCode(){
        if(Integer.MIN_VALUE == this.hashCode){
            if(null == this.getProductid()){
                return super.hashCode();
            }else{
                String hashStr = this.getClass().getName()+":"+this.getProductid().hashCode();
                this.hashCode  = hashStr.hashCode();
            }
        }
        return this.hashCode;
    }
    public boolean equals(Object obj){
        if(null == obj){
            return false;
        }
        if(!(obj instanceof Product)){
            return false;
        }
        Product mObj = (Product)obj;
        if(null == this.getProductid()|| null == mObj.getProductid()){
            return false;
        }else{
            return this.getProductid().equals(mObj.getProductid());
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?