Bonjour,

Je développe une application "eshop" en J2EE, avec GlassFish et Tomcat, avec des EJB, Struts, JSP.

Mon problème est que lorsque j'appelle une action pour enregistrer les données dans la base de données MySql, il me retourne ce message :
javax.servlet.ServletException: javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.0.v20090912-r5114): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/eshopSource].
Internal Exception: javax.naming.NameNotFoundException: Le Nom jdbc n'est pas lié à ce Contexte
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Quelqu'un saurait-il m'expliquer d'où peut venir ce problème ?

J'ai généré les entités qui m'ont permis de créer la base et j'ai configuré GlassFish et le nom de la base de données dans MySql est "eshop"

Voici le code de l'action :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package actions;
 
import java.util.Properties;
 
 
import javax.naming.InitialContext;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
 
import daoStateless.PromotionDao;
 
import entites.Promotion;
import forms.AjoutPromotionForm;
public class AjouterPromotion extends Action{
 
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
         Properties props = new Properties();
           props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
           props.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
           props.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
           props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
           props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
            try{
        InitialContext context = new InitialContext(props);
        System.out.println("loading context successufull");
        PromotionDao promotionDAO = (PromotionDao) context.lookup("java:global/EshopEJB/PromotionDaoRemote");
        AjoutPromotionForm myForm=(AjoutPromotionForm) form;
        Promotion promotion=new Promotion();
        promotion.setRemise(myForm.getRemise());
        promotion.setDateDebut(myForm.getDateDebut());
        promotion.setDateFin(myForm.getDateFin());
        promotionDAO.ajouterPromo(promotion);
 
            }
        catch(Exception e){
            System.out.print(e.getMessage());
        }
return mapping.findForward("success");
 
    }
 
}
PromotionDaoRemote est le stateless qui se trouve dans le projet EJB.
Voici son code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package daoStateless;
 
import java.util.List;
 
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
 
import entites.Promotion;
 
@Stateless(name="PromotionDaoRemote")
public class PromotionDaoImpl implements PromotionDao {
    @PersistenceContext(unitName="ESHOPDATAUNITE")
  public EntityManager em; 
 
 
    public Promotion find(int id){
        return em.find(Promotion.class, id);
    }
 
    public void update(Promotion p){
        em.merge(p);
    }
 
    public  void ajouterPromo(Promotion promo){
        em.persist(promo);
    }
 
 
    @SuppressWarnings("unchecked")
    public List<Promotion> selectAllPromo(){
        Query query = em.createQuery("select p from Promotion p");
        List resultList = query.getResultList();
        return resultList;
    }
 
 
    public void supprimerPromo(Promotion promo){        
                em.remove(promo);
    }
}
Merci d'avance pour votre aide.