Salve a tutti,

Spero di essere nella sezione giusta per chiedere aiuto al mio problema. Per un esame ci viene chiesto di sviluppare in Netbeans con Glassfish un applicazione Web.

Il mio problema stà nel fatto che, al momento del login, il browser mi solleva l'eccezione EJBException - HTTP STATUS - 500.

Vado quindi a vedere il file di log generato da Glassfish e trovo che il problema stà nel fatto che quando la servlet (LoginServlet) invoca GestioneLogin, che dovrebbe vedere se l'username inserito è o meno un utente, mi crea una lista <Utente> completamente vuota.

GestioneLogin

codice:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;


import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.ejb.EJBException;
import java.lang.RuntimeException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jpa.Admin;
import jpa.Commesso;
import jpa.Utente;

/**
 *
 * @author Simo
 */
@Stateless
public class GestioneLogin  implements GestioneLoginLocal {

    //@PersistenceContext
    private EntityManager em;

    @Override
    public Object executeLogin(String username, String password) throws  RuntimeException {
        try{
       // List<Admin> a = em.createNamedQuery("Admin.findById").setParameter("idid", username).getResultList();
//        List<Commesso> cu = em.createNamedQuery("Commesso.findByIdcommesso").setParameter("idcommesso", username).getResultList();
            List <Utente> cl = em.createNamedQuery("Utente.findByIdutente").setParameter("idutente", username).getResultList();

//        if (a == null && cu == null && cl == null) {
//            return null;
//        }
        System.out.println("questo e dopo il return "+username+"  "+password);
        String psw = hashPassword(password);
//        for (Admin ad:a) {
//           // if (ad.getPassword().equals(psw)) 
//                System.out.println("trovato admin "+ad.getNome());
//                return ad;
//            
//        }
//        for (Commesso cuo : cu) {
//            if (cuo.getPassword().equals(psw)) {
//                return cuo;
//            }
//        }
        for (Utente cli : cl) {
            if (cli.getPass().equals(psw)) {
                return cli;
            }
        }
   
        }catch(EJBException e){
            System.out.println("Errore ;"+e);
        }
        return null;

    }

    public static String hashPassword(String password) {
        String hashword = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            hashword = hash.toString(50);
        } catch (NoSuchAlgorithmException nsae) {
        }

        return hashword;
    }
    
}
Vi posto anche il codice dell'entità Utente:

codice:
package jpa;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Simo
 */
@Entity
@Table(name = "utente")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Utente.findAll", query = "SELECT u FROM Utente u"),
    @NamedQuery(name = "Utente.findByIdutente", query = "SELECT u FROM Utente u WHERE u.idutente = :idutente"),
    @NamedQuery(name = "Utente.findByPass", query = "SELECT u FROM Utente u WHERE u.pass = :pass")})
public class Utente implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 40)
    @Column(name = "idutente")
    private String idutente;
    @Size(min=1, max = 40)
    @Column(name = "pass")
    private String pass;

    public Utente() {
    }

    public Utente(String idutente) {
        this.idutente = idutente;
    }

    public String getIdutente() {
        return idutente;
    }

    public void setIdutente(String idutente) {
        this.idutente = idutente;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idutente != null ? idutente.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 Utente)) {
            return false;
        }
        Utente other = (Utente) object;
        if ((this.idutente == null && other.idutente != null) || (this.idutente != null && !this.idutente.equals(other.idutente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.Utente[ idutente=" + idutente + " ]";
    }
    
}
Qualcuno ha qualche idea in merito? Non sò più dove sbattere la testa sinceramente!!

Grazie mille a tutti