users@glassfish.java.net

NetBeans, Glassfish, J2EE Apllication.... I have a problem

From: <glassfish_at_javadesktop.org>
Date: Sat, 05 Jun 2010 11:31:42 PDT

Hi, I want to explain my problems.. I create a little project for test something to use in a big project. I have problem with persistence. It is impossible for me to make connection with DB.. I have a simply entity, a session bean, a jsp for call a servlet. When i try to make a persist(object) option they ever return a nullPointerException.. what is wrong on my project? thank you

@Entity
@Table(name="UTENTI")
public class Utente implements Serializable {
    @Id
    @Column(name="IDUTENTE")
    private String id;
    @Column(name="NOME")
    private String nome;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }
}
 
[b]A session bean[/b]

@Stateless(name="NewSessionBean")
public class NewSessionBean implements NewSessionBeanRemote {
    @PersistenceContext(name="EA1-ejbPU")
    private EntityManager em;

     public void Creazione(Utente u) throws IOException{
       try{
             em.persist(u);
           }catch (Exception ex) {
                      ex.printStackTrace();
           }finally {
               if(em != null) {
               em.close();
     } } }


[b]SERVLET[/b]

public class CreaUtenteServ extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     try{
        Utente u=new Utente();
        String id=request.getParameter("id");
        String nome=request.getParameter("nome");
        u.setId(id);
        u.setNome(nome);

        gestore.NewSessionBean cr=new gestore.NewSessionBean();
        cr.Creazione(u);

      }catch(Exception ex) {
            throw new ServletException(ex);
  } }
[Message sent by forum member 'maurotj84']

http://forums.java.net/jive/thread.jspa?messageID=472901