Java - Entities - User Info

Creating a user info class using entities in java.

Imports

package model.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

Entities

/* @author Steven Bartsch */
@Entity
@Table(name = "user_info")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserInfo.findAll", query = "SELECT u FROM UserInfo u"),
    @NamedQuery(name = "UserInfo.findByUserid", query = "SELECT u FROM UserInfo u WHERE u.userid = :userid"),
    @NamedQuery(name = "UserInfo.findByFirstname", query = "SELECT u FROM UserInfo u WHERE u.firstname = :firstname"),
    @NamedQuery(name = "UserInfo.findByLastname", query = "SELECT u FROM UserInfo u WHERE u.lastname = :lastname"),
    @NamedQuery(name = "UserInfo.findByStreet", query = "SELECT u FROM UserInfo u WHERE u.street = :street"),
    @NamedQuery(name = "UserInfo.findByPostalcode", query = "SELECT u FROM UserInfo u WHERE u.postalcode = :postalcode"),
    @NamedQuery(name = "UserInfo.findByCity", query = "SELECT u FROM UserInfo u WHERE u.city = :city"),
    @NamedQuery(name = "UserInfo.findByPhone", query = "SELECT u FROM UserInfo u WHERE u.phone = :phone")})

Members

public class UserInfo implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "userid")
    private Integer userid;
    @Column(name = "firstname")
    private String firstname;
    @Column(name = "lastname")
    private String lastname;
    @Column(name = "street")
    private String street;
    @Column(name = "postalcode")
    private String postalcode;
    @Column(name = "city")
    private String city;
    @Column(name = "phone")
    private String phone;

Methods

    public UserInfo(){
        firstname = "";
        lastname = "";
        street = "";
        postalcode = "";
        city = "";
        phone = "";
    }

    public UserInfo(String firstname, String lastname, String street, String postalcode, String city, String phone){
        this.firstname = firstname;
        this.lastname = lastname;
        this.street = street;
        this.postalcode = postalcode;
        this.city = city;
        this.phone = phone;
    }

    public UserInfo(Integer userid){
        this.userid = userid;
    }

    public Integer getUserid(){
        return userid;
    }

    public void setUserid(Integer userid){
        this.userid = userid;
    }

    public String getFirstname(){
        return firstname;
    }

    public void setFirstname(String firstname){
        this.firstname = firstname;
    }

    public String getLastname(){
        return lastname;
    }

    public void setLastname(String lastname){
        this.lastname = lastname;
    }

    public String getStreet(){
        return street;
    }

    public void setStreet(String street){
        this.street = street;
    }

    public String getPostalcode(){
        return postalcode;
    }

    public void setPostalcode(String postalcode){
        this.postalcode = postalcode;
    }

    public String getCity(){
        return city;
    }

    public void setCity(String city){
        this.city = city;
    }

    public String getPhone(){
        return phone;
    }

    public void setPhone(String phone){
        this.phone = phone;
    }

Overrides

    @Override
    public int hashCode(){
        int hash = 0;
        hash += (userid != null ? userid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object){
        if (!(object instanceof UserInfo)){
            return false;
        }
        UserInfo other = (UserInfo) object;
        if ((this.userid == null && other.userid != null) || (this.userid != null && !this.userid.equals(other.userid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString(){
        return "model.entities.UserInfo[ userid=" + userid + " ]";
    }
}