Vector cannot cast to IUser
<p>===============================</p>

<p>Now i have problem with Login page; Vector cannot cast to IUser</p>

<p>My Stateless Bean</p>

<pre><code>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.DAO;

import com.entity.IUser;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Kency
 */
@Stateless
@LocalBean
public class UserBean {
    @PersistenceContext(unitName = "mcGrawLibPro-ejbPU")
    private EntityManager em;


    public List&lt;IUser&gt; retrieveAllUser(){
        return em.createNamedQuery("IUser.findAll").getResultList();
    }

     public IUser userLogin(String username, String password){
    Query query = em.createNamedQuery("IUser.findByUsernameAndPassword");
    query.setParameter("username", username);
    query.setParameter("password", password);
    return  (IUser) query.getResultList();
   }

    public void persist(Object object) {
        em.persist(object);
    }

    public IUser findByID(Integer id){
        return em.find(IUser.class, id);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code &gt; Add Business Method")

}
</code></pre>

<p>and my JSF Managed Bean</p>

<pre><code>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mcgraw.controller;

import com.DAO.UserBean;
import com.entity.IUser;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Kency
 */
@ManagedBean
@SessionScoped
public class LoginController implements Serializable{
    @EJB
    private UserBean userBean;
    private IUser user;
    private boolean admin;
    private boolean mod;



    /** Creates a new instance of LoginController */
    public LoginController() {
        user = new IUser();

    }

    //getter / setter
     public boolean isMod() {
        return mod;
    }

    public void setMod(boolean mod) {
        this.mod = mod;
    }


    public IUser getUser() {
        return user;
    }

    public void setUser(IUser user) {
        this.user = user;
    }
    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }




     public String login() {

        user =  userBean.userLogin(user.getUsername(), user.getPassword());
        if (user != null) {
            setAdmin(user.getGroups().getAdmin());
            setMod(user.getGroups().getMod());
            return "home";
        } else {

            return "login";
        }
    }


    public String logout() {
        user = null;
        return "login";
    }

    public boolean isLoggedIn() {
        return user != null;
    }


}
</code></pre>

<p>My Entity Bean</p>

<pre><code>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Kency
 */
@Entity
@Table(name = "user")
@NamedQueries({
    @NamedQuery(name = "IUser.findAll", query = "SELECT i FROM IUser i"),
    @NamedQuery(name = "IUser.findByUserid", query = "SELECT i FROM IUser i WHERE i.userid = :userid"),
    @NamedQuery(name = "IUser.findByUsername", query = "SELECT i FROM IUser i WHERE i.username = :username"),
    @NamedQuery(name = "IUser.findByPassword", query = "SELECT i FROM IUser i WHERE i.password = :password"),
    @NamedQuery(name = "IUser.findByEmail", query = "SELECT i FROM IUser i WHERE i.email = :email"),
    @NamedQuery(name = "IUser.findByGender", query = "SELECT i FROM IUser i WHERE i.gender = :gender"),
    @NamedQuery(name = "IUser.findByDob", query = "SELECT i FROM IUser i WHERE i.dob = :dob"),
    @NamedQuery(name = "IUser.findByZipcode", query = "SELECT i FROM IUser i WHERE i.zipcode = :zipcode"),
    @NamedQuery(name = "IUser.findByIstate", query = "SELECT i FROM IUser i WHERE i.istate = :istate"),
    @NamedQuery(name = "IUser.findByAddress", query = "SELECT i FROM IUser i WHERE i.address = :address"),
    @NamedQuery(name = "IUser.findByCity", query = "SELECT i FROM IUser i WHERE i.city = :city"),
    @NamedQuery(name = "IUser.findByUsernameAndPassword", query = "SELECT i FROM IUser i WHERE i.username = :username AND i.password = :password "),
    @NamedQuery(name = "IUser.findByActive", query = "SELECT i FROM IUser i WHERE i.active = :active")})
public class IUser implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "userid")
    private Integer userid;
    @Basic(optional = false)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;
    @Basic(optional = false)
    @Column(name = "gender")
    private String gender;
    @Basic(optional = false)
    @Column(name = "dob")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dob;
    @Basic(optional = false)
    @Column(name = "zipcode")
    private int zipcode;
    @Basic(optional = false)
    @Column(name = "istate")
    private String istate;
    @Basic(optional = false)
    @Column(name = "address")
    private String address;
    @Basic(optional = false)
    @Column(name = "city")
    private String city;
    @Basic(optional = false)
    @Column(name = "active")
    private boolean active;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "iUser")
    private List&lt;Rent&gt; rentList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "iUser")
    private List&lt;Cart&gt; cartList;
    @JoinColumn(name = "igroup", referencedColumnName = "groupsid")
    @ManyToOne(optional = false)
    private Groups groups;

    public IUser() {
    }

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

     public IUser(String  username, String password) {
       this.username = username;
       this.password = password;
    }

    public IUser(Integer userid, String username, String password, String email, String gender, Date dob, int zipcode, String istate, String address, String city, boolean active) {
        this.userid = userid;
        this.username = username;
        this.password = password;
        this.email = email;
        this.gender = gender;
        this.dob = dob;
        this.zipcode = zipcode;
        this.istate = istate;
        this.address = address;
        this.city = city;
        this.active = active;
    }

    public Integer getUserid() {
        return userid;
    }

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

    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;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getDob() {
        return dob;
    }

    public void setDob(Date dob) {
        this.dob = dob;
    }

    public int getZipcode() {
        return zipcode;
    }

    public void setZipcode(int zipcode) {
        this.zipcode = zipcode;
    }

    public String getIstate() {
        return istate;
    }

    public void setIstate(String istate) {
        this.istate = istate;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

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

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public List&lt;Rent&gt; getRentList() {
        return rentList;
    }

    public void setRentList(List&lt;Rent&gt; rentList) {
        this.rentList = rentList;
    }

    public List&lt;Cart&gt; getCartList() {
        return cartList;
    }

    public void setCartList(List&lt;Cart&gt; cartList) {
        this.cartList = cartList;
    }

    public Groups getGroups() {
        return groups;
    }

    public void setGroups(Groups groups) {
        this.groups = groups;
    }

    @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 IUser)) {
            return false;
        }
        IUser other = (IUser) object;
        if ((this.userid == null &amp;&amp; other.userid != null) || (this.userid != null &amp;&amp; !this.userid.equals(other.userid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entity.IUser[userid=" + userid + "]";
    }

}
</code></pre>

<p>My Converter Class</p>

<pre><code>package com.mcgraw.controller;


import com.entity.IUser;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Kency
 */
@FacesConverter(forClass=IUser.class)
public class UserConverter  implements Converter{
    private IUser user;


    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {


        if(user == null){
        user = new IUser(Integer.valueOf(value));
        return user;
       }else{
        throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to User", value)));

       }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return String.valueOf(((IUser) value).getUserid());
    }

}
</code></pre>

<p>I have Error with Vector cannot cast to IUser
i dont know why it error?
i was create 1 class to convert IUser but why error ?
but when i change query.getResultlist() to ==> query.getSingleResult(); it work well 
why???
(Now i not yet to check user login or not just try create login page )</p>
