Java - Entities - User Account

Creating a user account 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_account")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserAccount.findAll", query = "SELECT u FROM UserAccount u"),
    @NamedQuery(name = "UserAccount.findByUserid", query = "SELECT u FROM UserAccount u WHERE u.userid = :userid"),
    @NamedQuery(name = "UserAccount.findByUserlevel", query = "SELECT u FROM UserAccount u WHERE u.userlevel = :userlevel"),
    @NamedQuery(name = "UserAccount.findByUsername", query = "SELECT u FROM UserAccount u WHERE u.username = :username"),
    @NamedQuery(name = "UserAccount.findByPassword", query = "SELECT u FROM UserAccount u WHERE u.password = :password"),
    @NamedQuery(name = "UserAccount.findByEmail", query = "SELECT u FROM UserAccount u WHERE u.email = :email")})

Members

public class UserAccount implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "userid")
    private Integer userid;
    @Column(name = "userlevel")
    private Integer userlevel;
    @Column(name = "username")
    private String username;
    @Column(name = "password")
    private String password;
    @Column(name = "email")
    private String email;

Methods

    public UserAccount(){
        userlevel = null;
        username = "";
        password = "";
        email = "";
    }

    public UserAccount(int userlevel, String username, String password, String email){
        this.userlevel = userlevel;
        this.username = username;
        this.password = password;
        this.email = email;
    }

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

    public Integer getUserid(){
        return userid;
    }

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

    public Integer getUserlevel(){
        return userlevel;
    }

    public void setUserlevel(Integer userlevel){
        this.userlevel = userlevel;
    }

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username = username;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password = password;
    }

    public String getEmail(){
        return email;
    }

    public void setEmail(String email){
        this.email = email;
    }

Overrides

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

    @Override
    public boolean equals(Object object){
        // TODO: Warning - this method won't work in the case the id fields are not set
        if(!(object instanceof UserAccount)){
            return false;
        }
        UserAccount other = (UserAccount) 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.UserAccount[ userid=" + userid + " ]";
    }
}