Java Enterprise Tutorial – Getting Started – Parte 2

Ora creiamo un package nel nostro modulo EJB facendo click destro su source Packages e poi su New->Package e chiamiamolo entity; successivamente, facendo click destro sul package appena creato, selezioniamo create new entity class from databases.
Nella finestra di dialogo selezioniamo la tabella user e clicchiamo su add e poi next, a questo punto ci viene chiesto come vogliamo chiamare la classe e in quale package posizionarla, lasciamo tutto di default e clicchiamo su finish.
Questa che è stata creata non è altro che una classe java che rispecchia la nostra tabella Users del DB, è per questo motivo che questi tipi di classi vengono chiamate Entity Bean proprio perchè rappresentano entità, ovvero copie in memoria di dati persistenti in una struttura dati.
Analizzando il codice potrete vedere che, a differenza di una normale classe java, sono presenti delle annotazioni precedute dalla @: queste servono a comunicare all’application server, e di conseguenza al gestore della persistenza, il legame tra l’oggetto e la relativa tabella del db.

firstclass

Non possiamo entrare nel dettaglio delle annotazioni altrimenti ci dilungheremmo troppo: chiunque volesse soddisfare la propria curiosità si può rifare alla specifiche sun.
Ora creiamo il nostro primo session Bean, creiamo un nuovo package cliccando con il tasto destro su source->packages e chiamiamolo session, facciamo click destro su quest’ultimo e selezioniamo New->Session Bean.
Chiamiamo il nostro bean UserServe, lasciamo la spunta su stateless,  spuntiamo entrambe le voci Remote e Local e clicchiamo su finish.
Abbiamo appena creato un session less bean ovvero un bean che non mantiene nessun valore in memoria e può essere usato contemporaneamente da più bean senza avere un rapporto uno ad uno con questi ultimi.
Noterete che sono stati creati tre file, uno è UserServeBean, l’oggetto vero e proprio in cui implementeremo i nostri metodi, e gli altri due sono le sue interfacce, una per accessi locali, ovvero dall’interno dello stesso modulo EJB, e uno per accessi remoti, ovvero dall’esterno del modulo.
Ora posizioniamoci con il mouse all’interno della classe appena creata e noteremo un commento
// Add business logic below. (Right-click in editor and choose
// “Insert Code > Add Business Method” or “Web Service > Add Operation”)

Seguiamo la prima indicazione, ovvero aggiungiamo un business method, in realtà possiamo scrivere il nostro metodo a mano, ma poi dovremmo riportarlo nelle due interfacce: usando questo tool, invece, esso verrà riportato nelle interfacce automaticamente.
Nella finestra di dialogo creiamo un metodo chiamato createUser passandogli come parametri i dati di un utente, esclusa la chiave, come tipo di ritorno settiamo boolean: ricordiamoci di spuntare il radio button in basso “Remote” e clicchiamo su finish.

metodo

Ora che abbiamo creato lo scheletro del nostro primo metodo bisognerà implementare l’effettiva scrittura: trattandosi di strumenti enterprise non dovremmo scrivere nessuna query, il tutto verrà demandato all’unità di persistenza.
Prepariamoci ad utilizzare l’EntityManager importando i seguenti pckages:

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

Ora diciamo al nostro bean come si chiama la persistence unit, prepariamo una variabile di tipo EntityManagerFactory e all’interno del nostro metodo inizializziamo una variabile di tipo EntityManager utilizzando la factory definita in precedenza.

emanager

Ora non resta altro che creare un oggetto di tipo Users con i parametri che ci vengono passati.
Ricordiamo di importare entity.Users ed utilizziamo il costruttore del nostro entity bean per creare l’oggetto.
Successivamente chiamiamo il metodo persist sull’oggetto EntityManager passandogli l’oggetto users appena creato.

persist1

Come potete notare il metodo persist è void ovvero non ci fornisce nessun ritorno di tipo boolean: per sapere se l’operazione è andata a buon fine bisogna intercettare le quattro possibili eccezioni che possono generarsi in questo tipo di contesto

EntityExistsException
IllegalStateException
IllegalArgumentException
TransactionRequiredException

Catturiamo le eccezioni con un try catch e all’interno dei vari catch valorizziamo una variabile booleana a false in modo da avere un ritorno negativo se si verifica una qualsiasi delle quattro eccezioni.
Di seguito potete vedere lo screenshot del metodo completo.

classe_completa

Ora possiamo dire che abbiamo creato il nostro primo modulo EJB funzionante, non ci resta che creare un Servlet sul progetto WAR che invochi il metodo CreateUser.
Spostiamoci sul progetto WAR e creiamo un nuovo package nella cartella source packages chiamandolo servlet, facendo clic destro su quest’ultimo selezioniamo New->Servlet, nella finestra di dialogo chiamiamo la nostra servlet doCreateUser, clicchiamo su next e nella finestra successiva lasciamo tutto com’è e clicchiamo su finish.
Abbiamo appena creato una servlet che sarà accessibile da browser con il nome /doCreateUser: non è lo scopo di questo tutorial spiegare cos’è una servlet o una pagina JSP, difatti si suppone che l’utente  dovrebbe già averne una conoscenza sufficiente per affrontare l’apprendimento della tecnologia Enterprise.
Ora facciamo click destro all’interno della classe e andiamo su InsertCode->Call Enterprise Bean, nella finestra di dialogo selezioniamo il bean, spuntiamo il radio button remote e clicchiamo ok.
Ora ci viene resa disponibile una variabile chiamata userServeBean di tipo UserServeRemote sulla quale possiamo chiamare il metodo createUser ed intercettarne il ritorno per stamparne l’esito a video.
Di seguito ecco il codice completo del metodo processRequest della servlet.

servlet

Prima di eseguire un test, sopratutto se utilizzate windows, è probabile che il connector mysql non sia presente in glassfish; per ovviare alla mancanza è sufficiente copiare il JAR di cui abbiamo parlato all’inizio del tutorial nella cartella lib del dominio in uso appartenente a glassfish
(Percorso di esempio : C:/Programmi/GlassfishV2/domains/domain1/lib)
Ora possiamo cliccare con il tasto destro sul progetto principale e selezionare Deploy, a questo punto netbeans creerà i pacchetti necessari e ne farà il deploy automatico su glassfish che nel frattempo verrà avviato.
Nelle finestra output in basso è presente la tab GlassFishV2 che stampa l’output dell’application server, in caso di errore è in quest’ultima che potremo leggere i dettagli di eventuali eccezioni.
Se tutto è andato a buon fine dovrebbe apparire nella finestra output un BUILD SUCCESFULL:
ora possiamo lanciare il progetto cliccando sulla freccia verde in alto oppure con il tasto destro sul progetto principale MyFirstJEE e poi Run.
Si aprirà il browser di default del sistema mostrando una pagina Hello Word!
Ora che il nostro dominio web è avviato non dobbiamo far altro che richiamare la nostra servlet aggiungendo all’url “doCreateUser” sperando che la finestra che vi verrà mostrata sia questa:

pagina

Bene, siamo arrivati alla fine di questo primo tutorial, che spero vi sia servito a prendere dimestichezza con l’ambiente enterprise e che sopratutto sia stato un utile esercizio per cominciare a comprenderne le logiche.
Restano ancora da affrontare argomenti basilari come l’estrazione dei dati attraverso le NamedQuery o attraverso le NativeQuery e come utilizzare, e quando, un bean di tipo session full: ma questi saranno argomenti per un altro tutorial.
In caso di problemi postate pure un commento e sarò felice di aiutarvi!!
Vi ricordo che potete scaricare il progetto netbeans completo di questo tutorial cliccando qui!

  • Alberto

    Ciao, ho seguito il tuo tutorial per la creazione di questa prima applicazione Enterprise e lo trovo molto utile. Mi trovo però di fronte ad un errore quando vado ad eseguirlo; lo stesso errore lo rilevo sia con la mia applicazione che ho sviluppato seguendo passo passo le tue spiegazioni sia sulla tua applicazione che ho scaricato dal link sopra ed eseguito sul mio NetBeans. A questo punto immagino che il problema sia dovuto al mio server; l’errore che rileva quando vado ad aggiungere all’url /doCreateUser è il seguente:

    type Exception report

    message

    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException

    sapresti dirmi a cosa è dovuto?! Ti ringrazio 😉

  • Mauro Rocco

    Per risalire all’errore corretto dovresti inviarmi i log di errore di glassfish e non solo quelli stampati nella pagina web.
    Se hai difficoltà a trovarli ti dico subito che netbeans stampa lo stack trace, e in generale tutti gli output, nella tab in basso chiamata “GlassFish V2”.
    Con questi log sono in grado di dirti con più precisione dove può essere il problema.
    Riavvia GlassFish (o Netbeans del tutto) e ripeti le operazioni che ti portano all’errore, appena ti appare ritorna in netbeans copia lo stack completo dell’eccezzione e postamelo (Sarà certamente molto lungo).

  • Alberto

    Ciao, ti ringrazio per avermi risposto e per la velocità in cui l’hai fatto; questo di seguito è l’output di Glassfish dal load dell’applicazione in poi…
    Grazie ancora.

    deployed with moduleid = EnterpriseApplication
    **RemoteBusinessJndiName: session.UserServeRemote; remoteBusIntf: session.UserServeRemote
    LDR5010: All ejb(s) of [EnterpriseApplication] loaded successfully!
    EJB5018: An exception was thrown during an ejb invocation on [UserServeBean]
    javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3894)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3794)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3596)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1379)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:210)
    at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
    at $Proxy43.createUser(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:233)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
    at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
    at session.__UserServeRemote_Remote_DynamicStub.createUser(session/__UserServeRemote_Remote_DynamicStub.java)
    at session._UserServeRemote_Wrapper.createUser(session/_UserServeRemote_Wrapper.java)
    at servlet.doCreateUser.processRequest(doCreateUser.java:36)
    at servlet.doCreateUser.doGet(doCreateUser.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.lang.NullPointerException
    at session.UserServeBean.createUser(UserServeBean.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
    … 43 more
    StandardWrapperValve[doCreateUser]: PWC1406: Servlet.service() for servlet doCreateUser threw exception
    javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:747)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:243)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
    at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
    at session.__UserServeRemote_Remote_DynamicStub.createUser(session/__UserServeRemote_Remote_DynamicStub.java)
    at session._UserServeRemote_Wrapper.createUser(session/_UserServeRemote_Wrapper.java)
    at servlet.doCreateUser.processRequest(doCreateUser.java:36)
    at servlet.doCreateUser.doGet(doCreateUser.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    at session.UserServeBean.createUser(UserServeBean.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
    at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
    at $Proxy43.createUser(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:233)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
    at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
    at session.__UserServeRemote_Remote_DynamicStub.createUser(session/__UserServeRemote_Remote_DynamicStub.java)
    at session._UserServeRemote_Wrapper.createUser(session/_UserServeRemote_Wrapper.java)
    at servlet.doCreateUser.processRequest(doCreateUser.java:36)
    at servlet.doCreateUser.doGet(doCreateUser.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException
    at session._UserServeRemote_Wrapper.createUser(session/_UserServeRemote_Wrapper.java)
    at servlet.doCreateUser.processRequest(doCreateUser.java:36)
    at servlet.doCreateUser.doGet(doCreateUser.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

  • Alberto

    Ho risoltoooooo :) avevo dimenticato di richiamare la persistence unit all’interno dell Session Bean, grazie mille per la tua disponibilità, penso che ora seguirò i tutorial seguenti….

  • Mauro Rocco

    Bene ne sono felice!
    Se avessi usato il progetto scaricato non avresti avuto problemi, ma il tuo approccio è sempre quello che consiglio, ci si sbatte la testa ma quando si arriva alla soluzione cè tutta un’altra soddisfazione. :-)

  • Alberto

    già, infatti la penso anche io così…ti faccio un esempio: in ufficio sto lavorando su un progetto e devo caricare dei dati da un file XML; volendo avrei la soluzione pronta tramite delle librerie sviluppate da un mio collega ma ci sto sbattendo la testa per poterlo risolvere io 😉

  • Enrico

    Ciao, ho seguito tutta la guida, per provare il tutto richiamo da una sevlet un metodo del session bean. Facendo il build del progetto mi da i seguenti errori

    Note: Creating static metadata factory …
    Note: Building metadata class for round element: mobi.smsit.Rubrica.model.session.ContactManagerBean
    Note: Optional file was not found: META-INF/orm.xml continuing with generation.
    Note: Optional file was not found: META-INF/eclipselink-orm.xml continuing with generation.

    nel file persistence.xml il persistence provider è settato a EclipseLink(JPA 2.0)

  • Enrico

    Ho eseguito tutta la guida ma il server mi questo errore:

    INFO: Portable JNDI names for EJB ContactManager :
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: Loading application Rubrica#Rubrica-war.war at Rubrica-war
    INFO: Rubrica was successfully deployed in 844 milliseconds.
    INFO: mobi.smsit.Rubrica.model.entity.Contacts actually got transformed
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: EclipseLink, version: Eclipse Persistence Services – 2.0.1.v20100213-r6600
    GRAVE: RAR5099 : Wrong class name or classpath for Datasource Object
    java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.sun.gjc.common.DataSourceObjectBuilder.getDataSourceObject(DataSourceObjectBuilder.java:279)
    at com.sun.gjc.common.DataSourceObjectBuilder.constructDataSourceObject(DataSourceObjectBuilder.java:108)
    at com.sun.gjc.spi.ManagedConnectionFactory.getDataSource(ManagedConnectionFactory.java:1168)
    at com.sun.gjc.spi.DSManagedConnectionFactory.getDataSource(DSManagedConnectionFactory.java:135)
    at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:90)
    at com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator.createResource(LocalTxConnectorAllocator.java:73)
    at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:841)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1110)
    at com.sun.enterprise.resource.pool.datastructure.ListDataStructure.addResource(ListDataStructure.java:121)
    at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:277)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1404)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:869)
    at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:229)
    at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:455)
    at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:369)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:226)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:150)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:327)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:290)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:182)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:159)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:154)
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:105)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.createEntityManager(EntityManagerFactoryWrapper.java:101)
    at mobi.smsit.Rubrica.model.session.ContactManager.newContact(ContactManager.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
    at $Proxy146.newContact(Unknown Source)
    at mobi.smsit.Rubrica.controller.ServletController.processRequest(ServletController.java:66)
    at mobi.smsit.Rubrica.controller.ServletController.doGet(ServletController.java:151)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:636)

    AVVERTENZA: RAR5038:Unexpected exception while creating resource for pool mysql_Rubrica_rootPool. Exception : javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    AVVERTENZA: RAR5117 : Failed to obtain/create connection from connection pool [ mysql_Rubrica_rootPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    AVVERTENZA: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource]
    GRAVE: Local Exception Stack:
    Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:309)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:138)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.createEntityManager(EntityManagerFactoryWrapper.java:101)
    at mobi.smsit.Rubrica.model.session.ContactManager.newContact(ContactManager.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
    at $Proxy146.newContact(Unknown Source)
    at mobi.smsit.Rubrica.controller.ServletController.processRequest(ServletController.java:66)
    at mobi.smsit.Rubrica.controller.ServletController.doGet(ServletController.java:151)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:636)
    Caused by: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:112)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
    … 62 more

    AVVERTENZA: A system exception occurred during an invocation on EJB ContactManager method public boolean mobi.smsit.Rubrica.model.session.ContactManager.newContact(int,java.lang.String,java.lang.String)
    javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
    at $Proxy146.newContact(Unknown Source)
    at mobi.smsit.Rubrica.controller.ServletController.processRequest(ServletController.java:66)
    at mobi.smsit.Rubrica.controller.ServletController.doGet(ServletController.java:151)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:636)
    Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    Error Code: 0
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:397)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.createEntityManager(EntityManagerFactoryWrapper.java:101)
    at mobi.smsit.Rubrica.model.session.ContactManager.newContact(ContactManager.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
    … 30 more
    Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:309)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:138)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
    … 57 more
    Caused by: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:112)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
    … 62 more

    AVVERTENZA: StandardWrapperValve[ServletController]: PWC1406: Servlet.service() for servlet ServletController threw exception
    javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
    at $Proxy146.newContact(Unknown Source)
    at mobi.smsit.Rubrica.controller.ServletController.processRequest(ServletController.java:66)
    at mobi.smsit.Rubrica.controller.ServletController.doGet(ServletController.java:151)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:636)
    Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    Error Code: 0
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:397)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.createEntityManager(EntityManagerFactoryWrapper.java:101)
    at mobi.smsit.Rubrica.model.session.ContactManager.newContact(ContactManager.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
    … 30 more
    Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:309)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:138)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
    … 57 more
    Caused by: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:112)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
    … 62 more

  • Mauro Rocco

    Enrico, ogni eccezione che ti vien fuori la posti qui senza perderci un pò di tempo ? :-)
    Comunque il motivo dell’ultima eccezione sembra chiaro

    [Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource]

    Ora avendo solo l’eccezione non posso aiutarti più di tanto,comunque spesso questa eccezione viene fuori quando su glassfish non è installato il driver mysql, verifica che ci sia.

  • giovanni

    Ciao, ti ringrazio per questa utilissima guida .

    Ho un problema , quando vado a creare un nuovo session bean , Netbeans non mi lascia selezionare la casellina “remote” , se la seleziono mi impedisce la creazione del sessionbean stampando la seguente eccezione:

    There is no suitable project available into which Remote interface could be stored. An open Ant-based Java Class Library project is required.

    Spero tu possa aiutarmi , ti ringrazio, Giovanni

  • Mauro Rocco

    @giovanni questo tutorial e’ ormai datato e non conoscendo il tuo setup non so se posso aiutarti. In ogni caso Remote e Local sono solo interfacce, che puoi eventualmente creare manualmente in un secondo momento. Il tipo di errore mi suggerisce che c’e’ qualcosa di diverso nel tuo setup, e’ anche probabile che tu stia lavorando con una versione piu’ nuova delle specifiche j2ee.

  • Giovanni

    Grazie per la risposta Mauro , si io ho una versione più nuova delle specifiche j2ee.
    Comunque ho creato il progetto passo passo , faccio il deploy e non mi da nessuno errore .
    Unica cosa quando lo eseguo piuttosto di visualizzare la stringa “Utente creato con successo” ,
    visualizza “Hello world”. Ho controllato e ricontrollato tutto , proprio non riesco a capire come mai.

  • Giovanni

    Questo è il risultato di glassfish:WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41].
    WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41] from index [0]
    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1cc5527] from index [1]
    INFO: EJB5181:Portable JNDI names for EJB UserServe:
    INFO: WEB0671: Loading application [MyFirstJEE#MyFirstJEE-war.war] at [MyFirstJEE-war]
    INFO: Distribuzione di MyFirstJEE riuscita in 368 millisecondi.
    INFO: keepstate options resolved to true, saving appId 88606041202360320 for application MyFirstJEE.
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU logout successful
    INFO: entity.Users actually got transformed
    INFO: EclipseLink, version: Eclipse Persistence Services – 2.3.2.v20111125-r10461
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU login successful
    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41].
    WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41] from index [0]
    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1cc5527] from index [1]
    INFO: EJB5181:Portable JNDI names for EJB UserServe:
    INFO: WEB0671: Loading application [MyFirstJEE#MyFirstJEE-war.war] at [MyFirstJEE-war]
    INFO: Distribuzione di MyFirstJEE riuscita in 666 millisecondi.
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    WARNING: java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1815)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

    SEVERE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
    java.lang.Exception: java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

    SEVERE: Exception while loading the app
    SEVERE: Exception while loading the app : java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU logout successful
    INFO: entity.Users actually got transformed
    INFO: EclipseLink, version: Eclipse Persistence Services – 2.3.2.v20111125-r10461
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU login successful
    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41].
    WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41] from index [0]
    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1cc5527] from index [1]
    INFO: EJB5181:Portable JNDI names for EJB UserServe:
    INFO: WEB0671: Loading application [MyFirstJEE#MyFirstJEE-war.war] at [MyFirstJEE-war]
    INFO: Distribuzione di MyFirstJEE riuscita in 371 millisecondi.
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    WARNING: java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1815)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

    SEVERE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
    java.lang.Exception: java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

    SEVERE: Exception while loading the app
    SEVERE: Exception while loading the app : java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU logout successful
    INFO: entity.Users actually got transformed
    INFO: EclipseLink, version: Eclipse Persistence Services – 2.3.2.v20111125-r10461
    INFO: file:/C:/Users/giovanni/Documents/NetBeansProjects/MyFirstJEE/dist/gfdeploy/MyFirstJEE/MyFirstJEE-ejb_jar/_MyFirstJEE-ejbPU login successful
    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41].
    WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41] from index [0]
    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1cc5527] from index [1]
    INFO: EJB5181:Portable JNDI names for EJB UserServe:
    INFO: WEB0671: Loading application [MyFirstJEE#MyFirstJEE-war.war] at [MyFirstJEE-war]
    INFO: Distribuzione di MyFirstJEE riuscita in 432 millisecondi.

    Spero tu possa aiutarmi , in ogni caso ti ringrazio. Saluti Giovanni

  • Giovanni

    Scusa se sto postando troppi commenti, ti chiede di prendere in considerazione SOLO QUESTO ULTIMO .
    Aggiungendo al link “doCreateUser” viene visualizzata la stringa “Utente creato con successo”.

    Il problema è che quando faccio il deploy, nella finestra [MyFirstJEE(run-deploy)]
    il risultato è quello atteso:COSTRUITO CON SUCCESSO.

    Mentre nella finestra di GlassFish , anche se alla fine stampa “Distribuzione di MyFirstJEE riuscita in 380 millisecondi.”
    prima da diversi errori.

    Questi sono gli errori:
    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41].
    WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@1326a41] from index [0]
    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1cc5527] from index [1]
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    SEVERE: Class [ Lsession/UserServeLocal; ] not found. Error while loading [ class servlet.doCreateUser ]
    WARNING: java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.
    SEVERE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
    SEVERE: Exception while loading the app
    SEVERE: Exception while loading the app : java.lang.Exception: WEB0113: Virtual server [server] already has a web module [MyFirstJEE-war.war] loaded at [/MyFirstJEE-war]; therefore web module [MyFirstJEE-war] cannot be loaded at this context path on this virtual server.

    Spero tu possa aiutarmi , la tua guida mi è stata utilissima e vorrei concluderla con sucesso… saluti Giovanni

  • Mauro Rocco

    @giovanni prova a fare l’undeploy manuale da glassfish accedendo al web panel. In questo modo ti assicuri che sul server non ci sono altre versioni del war.

  • Tony

    ciao ottima guida
    avevo dei problemi col mio progetto e ho cercato su internet delle soluzioni invano. poi ho provato a fare questo per vedere se dipendesse da errori nel codice o da qualche settaggio sbagliato..o da qualche servizio bloccato da windows non so
    e purtroppo mi riporta gli stessi errori, te ne elenco qualcuno

    WARNING: RAR8068: Using default datasource : __ds_jdbc_ra for pool : mysql_mydb_rootPool

    WARNING: RAR8068: Using default datasource : __ds_jdbc_ra for pool : mysql_mydb_rootPool

    INFO: entity.Users actually got transformed

    INFO: EclipseLink, version: Eclipse Persistence Services – 2.3.2.v20111125-r10461

    SEVERE: RAR5099 : Wrong class name or classpath for Datasource Object

    WARNING: RAR5038:Unexpected exception while creating resource for pool mysql_mydb_rootPool. Exception : javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

    WARNING: RAR5117 : Failed to obtain/create connection from connection pool [ mysql_mydb_rootPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

    SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method

    SEVERE: Exception while invoking class org.glassfish.javaee.full.deployment.EarDeployer prepare method

    SEVERE: Exception while preparing the app

    SEVERE: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseExceptionWARNING: RAR5114 : Error allocating connection : [Errore durante l’allocazione di una connessione. Causa: Class name is wrong or classpath is not set for : com.mysql.jdb
    java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource

    e molti altri.. se hai tempo dacci un occhiata
    ciao e grazie in anticipo

  • fireantology

    Ciao Tony,

    Sei sicuro di aver installato su Glassfish il connector Mysql ? Sembra che non riesca a trovarlo.

    javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

  • Tony

    ci ho provato
    ho copiato il jar nella libreria di glassfish e ho provat ad aggiungere il connection pool nel pannello di amministrazione di glassfish ma quando provo a fare ping per vedere se è tutto apposto mi da nuovamente errore “Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource”

    riprovo intanto

  • Tony

    ho provato a reinstallare mysql server
    e riporta un errore durante la configurazione del server

    mysql-server-5.6-winx64:93 – Attempting to Add New MySQL Users

    mysql-server-5.6-winx64:100 – Unable to add New Users. Access denied for user ‘root’@’localhost’ (using password: YES)

    mysql-server-5.6-winx64:100 – Product configuration controller finished configuration.

  • fireantology

    Questo sembra essere solo un problema di accesso a mysql. L’utente root non riesce ad accedere il db, assicurati di aver inserito la giusta password nelle configurazioni. Attenzione che quando non usi password puoi avere dei problemi con il connector quindi in caso il tuo utente root di mysql sia senza password ti consiglio di settarne una.

  • Tony

    la password l’ho settata.. infatti se non la metto da glassfish esce l’errore “inserire password”..
    sarà un bel pomeriggio

  • Tony

    ho risolto (non chiamano il bean giusto)

    comunque non riesce a fare il persist quando accedo alla servlet
    Internal Exception: java.sql.SQLException: No database selected
    Error Code: 1046

  • fireantology

    Anche qui sembra solo un problema di configurazione hai creato il Database Schema come nella prima parte del tutorial ? Assicurati che la stringa di connessioni sia in questo formato jdbc:mysql://Server IP address:3306/Database Name