Précédent   Forum des professionnels en informatique > Java > Développement Web en Java
Développement Web en Java Forum d'entraide sur les technologies Web de Java (JSP/Servlets, Portlets, Applets, frameworks Web, etc.) Avant de poster -> FAQ Java EE
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/01/2012, 11h53   #1
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Par défaut JPA / J2EE utilisation de find()

Bonjour !

après plusieurs jours de recherches infructueuses sur divers forum et tutoriels, j'en suis réduit à poster ce message sos :

je n'arrive désespérément pas à utiliser correctement la méthode find() dans mon application.

j'ai suivi consciencieusement le tutoriel suivant :
http://wwwdi.supelec.fr/hardebolle/t...JEE_43-jpa.php

mais bien évidemment, il me manque certainement LE pré-requis nécessaire...

Quelqu'un peut-il m'aider ?

Au besoin je peux envoyer le code source de mon application pour tenter de comprendre...


Merci beaucoup d'avance

jean-Michel
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 12h09   #2
Membre émérite
 
Avatar de anisj1m
 
Homme
Ingénieur développement logiciels
Inscription : juillet 2006
Messages : 1 055
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 29
Localisation : Tunisie

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juillet 2006
Messages : 1 055
Points : 929
Points : 929
Envoyer un message via Yahoo à anisj1m
euhhhh tu n'as mentionné aucune erreur
Et quelle est votre erreur
__________________
Ce qu'on appelons le hasard n'est que notre incapacité à comprendre un degré d'ordre supérieur.
anisj1m est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 12h15   #3
Expert Confirmé
 
Homme
Ingénieur développement logiciels
Inscription : juin 2007
Messages : 2 258
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : juin 2007
Messages : 2 258
Points : 2 578
Points : 2 578
Citation:
Envoyé par jmdel5327 Voir le message
Bonjour !

après plusieurs jours de recherches infructueuses sur divers forum et tutoriels, j'en suis réduit à poster ce message sos :

je n'arrive désespérément pas à utiliser correctement la méthode find() dans mon application.

j'ai suivi consciencieusement le tutoriel suivant :
http://wwwdi.supelec.fr/hardebolle/t...JEE_43-jpa.php

mais bien évidemment, il me manque certainement LE pré-requis nécessaire...

Quelqu'un peut-il m'aider ?

Au besoin je peux envoyer le code source de mon application pour tenter de comprendre...


Merci beaucoup d'avance

jean-Michel
Peux tu nous poster ton code ne marchant pas, et les traces d'erreur d'éxécution?
DevServlet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 18h36   #4
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Par défaut voilà mon code :

fichier categorie.java
Code :
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;
 
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
//import javax.persistence.Entity;
import javax.persistence.*;
//import javax.persistence.Table;
 
@Entity
@Table(name = "categorie")
 
 
 
public class categorie implements Serializable {
    @Id
 
    public int catid;
    public String catnom;
 
 
public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
    private String sampleProperty;
    private PropertyChangeSupport propertySupport;
 
    public categorie() {
        propertySupport = new PropertyChangeSupport(this);
    }
 
    public String getSampleProperty() {
        return sampleProperty;
    }
 
    public void setSampleProperty(String value) {
        String oldValue = sampleProperty;
        sampleProperty = value;
        propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
    }
 
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
 
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    } 
 
    public void setId(int tpid) {
       catid = tpid; 
    }
    public int getId(){
        return catid;
    }
 
    public void setCatNom(String tpcatnom){
        catnom = tpcatnom;
    }
    public String getCatNom(){
        return catnom;
    }
 
    public int getCatid() {
        return catid;
    }
 
    public void setCatid(int catid) {
        this.catid = catid;
    }
 
}
fichier CatalogManager.java
Code :
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package logic;
 
import java.beans.*;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import model.categorie;
 
 
 
@ManagedBean
@ApplicationScoped
@EJB    
 
 
 
/**
 *
 * @author jm
 */
 
 
 
public class CatalogManager implements Serializable {
 
    private categorieFacade catfacade;
    private ArrayList<categorie> arListCategorie = new ArrayList<categorie>()  ;
    private String transfert;
 
    private int transCategorieId;
    private String transCategorieNom;
 
    public void setTransfert(String transfert){
        this.transfert = transfert;
    }
 
    public String getTransfert(){
        return transfert;
    }   
 
    public void setTransCategorieId(int transCategorieId){
        this.transCategorieId = transCategorieId;
    }
    public int getTransCategorieId(){
        return transCategorieId;
    }
 
    public void setTransCategorieNom(String transCategorieNom){
        this.transCategorieNom = transCategorieNom;
    }
    public String getTransCategorieNom(){
        return transCategorieNom;
    }
 
 
    public void setArListCategorie(ArrayList<categorie> arListCategorie) {
       this.arListCategorie = arListCategorie; 
    }
 
    public ArrayList<categorie> getArListCategorie(){
        return arListCategorie;
    }
 
    public void CreateCategorie(){     
 
        categorie transCategorie = new categorie();
        transCategorie.catid = transCategorieId;
        transCategorie.catnom = transCategorieNom;
 
        arListCategorie.add(transCategorie);
 
    }
 
    public void ModifTransfert(){     
        //this.transfert=transfert;
    }    
 
    public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
    private String sampleProperty;
    private PropertyChangeSupport propertySupport;
 
    public CatalogManager() {
        propertySupport = new PropertyChangeSupport(this);
    } 
 
    public String getSampleProperty() {
        return sampleProperty;
    }
 
    public void setSampleProperty(String value) {
        String oldValue = sampleProperty;
        sampleProperty = value;
        propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
    }
 
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
 
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
 
    @PostConstruct
        public void initcategorie(){
        transfert = "salut !";
 
 
       //categorie nouveau = new categorie();
 
        //nouveau.catid=1;
        //nouveau.catnom = "vapeur";      
        //this.arListCategorie.add(nouveau);
 
 
        //categorie plus = new categorie();
        //plus.catid=2;
        //plus.catnom = "diesel";  
        //this.arListCategorie.add(plus);
        //String prov=null;
        //categorie data = new categorie();
        int ptl=1;
 
 
        categorie data=catfacade.find(ptl);
        this.arListCategorie.add(data);
 
 
    }
 
 
}
fichier categorieFacade.java
Code :
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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;
 
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import model.categorie;
 
/**
 *
 * @author jm
 */
@Stateless
public class categorieFacade extends AbstractFacade<categorie> {
    @PersistenceContext(unitName = "geRezaPU")
    private EntityManager em;
 
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
 
    public categorieFacade() {
        super(categorie.class);
    }
 
}
Voilà, je pense avoir mis le nécessaire...
C'est cette ligne là
categorie data=catfacade.find(ptl);
du fichierCatalogManager.java qui me pose du soucis.

catfacade.find(ptl)

Dans cette expression, il manque certainement un argument, puisque ça plante à l'exécution avec comme message :
Erreur lors de l?injection de ressources dans le bean géré «catalogManager»
Caused by: java.lang.NullPointerException
at logic.CatalogManager.initcategorie(CatalogManager.java:128)

Ou alors, il y a quelque chose que je n'ai pas compris du tout...

Merci encore de m'aider !!!!

jean-Michel

Je m'en souviendrai, quand plus tard, devenu pro moi aussi, je pourrais aider des débutants en Java...
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 21h25   #5
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Et quand j'essaye ça :
categorie data=catfacade.find(categorie.class, ptl);

Netbeans me dit :
method find in class logic.AbstractFacade<T> cannot be applied to given types;
required: java.lang.Object
found: java.lang.Class<model.categorie>,int
reason: actual and formal argument lists differ in length

???
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 08h58   #6
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
Il faudrait le code de AbstractFacade
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 11h04   #7
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Code de AbstractFacade.java

Code :
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
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;
 
import java.util.List;
import javax.persistence.EntityManager;
 
/**
 *
 * @author jm
 */
public abstract class AbstractFacade<T> {
    private Class<T> entityClass;
 
    public AbstractFacade(Class<T> entityClass) {
        this.entityClass = entityClass;
    }
 
    protected abstract EntityManager getEntityManager();
 
    public void create(T entity) {
        getEntityManager().persist(entity);
    }
 
    public void edit(T entity) {
        getEntityManager().merge(entity);
    }
 
    public void remove(T entity) {
        getEntityManager().remove(getEntityManager().merge(entity));
    }
 
    public T find(Object id) {
        return getEntityManager().find(entityClass, id);
    }
 
    public List<T> findAll() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        return getEntityManager().createQuery(cq).getResultList();
    }
 
    public List<T> findRange(int[] range) {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        javax.persistence.Query q = getEntityManager().createQuery(cq);
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        return q.getResultList();
    }
 
    public int count() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
        javax.persistence.Query q = getEntityManager().createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
 
}
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 11h30   #8
Expert Confirmé
 
Homme
Ingénieur développement logiciels
Inscription : juin 2007
Messages : 2 258
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : juin 2007
Messages : 2 258
Points : 2 578
Points : 2 578
Voila ton appel :
Code :
categorie data=catfacade.find(categorie.class, ptl);
et voila ce qui est défini dans ton abstractFacade :
Code :
1
2
3
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
Et voila la correction à apporter :
Code :
1
2
3
public T find(Class entityClass, Object id) {
return getEntityManager().find(entityClass, id);
}
Mais normalement tu devrais même pas pouvoir compiler ton projet avant éxécution. T'utilises un éditeur de fichiers plats pour ton dev?
DevServlet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 11h44   #9
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
Citation:
Envoyé par DevServlet Voir le message
Voila ton appel :
Code :
categorie data=catfacade.find(categorie.class, ptl);
et voila ce qui est défini dans ton abstractFacade :
Code :
1
2
3
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
Et voila la correction à apporter :
Code :
1
2
3
public T find(Class entityClass, Object id) {
return getEntityManager().find(entityClass, id);
}
Mais normalement tu devrais même pas pouvoir compiler ton projet avant éxécution. T'utilises un éditeur de fichiers plats pour ton dev?
non, je ne suis pas d'accord, les méthodes sont bonnes.
par contre, tu ne testes pas le fait que la clé n'existe pas, ton find peut renvoyer null
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 11h50   #10
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Netbeans ne veut pas

il me répond :
Code :
1
2
3
4
 
incompatible types found   : 
java.lang.Object required: 
T     return getEntityManager().find(entityClass, id);
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 12h28   #11
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
Tu devrais choisir un type d'objet pour la clé plutôt qu'un primitif.
Dans ta base de données, la clé est de type Integer ou autre ?
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 17h26   #12
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
oui, la clef est de type integer...

Merci de passer du temps pour m'aider !
J'espère que je vais m'en sortir...
J'ai développé longtemps en Pascal, d'abord Turbo-Pascal puis Delphi puis Lazarus, mais avec Java, je suis vraiment perdu...

Jean-Michel
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 17h59   #13
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
J'ai essayé ça :
Code :
1
2
3
4
 
    public T find(Class entityClass, Object id) {
        return (T) getEntityManager().find(entityClass, id);
    }


Il n'y a plus de message d'erreur à l'écriture ni à la compilation, mais à l'exécution, ça donne :
Code :
1
2
Caused by: java.lang.NullPointerException
	at logic.CatalogManager.initcategorie(CatalogManager.java:129)
ça plante toujours sur la ligne

Code :
categorie data=catfacade.find(categorie.class, 1);
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 09h29   #14
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
As-tu modifié le mapping pour mettre un Integer au lieu du int ?
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 10h03   #15
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
Je ne sais pas.

J'ai essayé "double" au moins c'est écrit identique,
J'ai essayé String puisque String est un objet,

mais le prblm reste le même
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 10h45   #16
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
mais non, ça ne colle pas... ta base dit : Integer
mappe donc ton champ en Integer et dans ton code, fait un
Code :
1
2
3
4
5
...
categorie data = catfacade.find(new Integer(1));
if (data != null)
{
   this.arListCategorie.add(data);}
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 11h49   #17
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
J'ai essayé, sans meilleurs résultats.
j'ai essayé aussi en remplaçant tous les "int" correspondants dans le code par Integer, cela ne change rien.

Je devrais peut-être signaler aussi une autre erreur (non blocante, mais est-ce lié ?)
sur les lignes suivantes :

Code :
1
2
3
4
5
6
 
public class categorie implements Serializable {
//    @Id @Column(name="catid") public Integer catid;
//    @Column(name="catnom") public String catnom;
    @Id public Integer catid;
    public String catnom;
Netbeans m'indique :
"instance variable for a persistent attribute must be not public"
ça marche quand même, mais dans la page d'erreur, en plus de :
Caused by: java.lang.NullPointerException
at logic.CatalogManager.initcategorie(CatalogManager.java:132)

il y a :
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting invoke lifecycle method public void logic.CatalogManager.initcategorie()

Evidemment, si je remplace public par private, cela me génère d'autres erreurs dans le fichier CatalogManager...

Au passage, j'ai essayé ça aussi :

Code :
1
2
3
categorie data = catfacade.find(categorie.class, new Integer(1));
        if (data != null)
            { this.arListCategorie.add(data);}
en modifiant le code dans AbstractFacade comme expliqué précédemment.

J'ai aussi vérifié ma base de données dans Glassfich où j'ai bien deux enregistrements. Là aussi, j'ai tenté différentes configurations dans la table et testé différents paramètres et clefs possibles, bien évidemment en revenant à la configuration d'origine pour ne pas me perdre.

C'est quand même étrange qu'un simple accès à une base de données soit aussi complexe à mettre en oeuvre.
le reste de mon apprentissage, accès réservé avec login, affichage de formulaires etc, ne pose pas particulièrement de problèmes.
Je suis prêt à réécrire mon ancien programme Pascal en java, si ce n'est ce "petit" écueil.
Mais l'actualité récente montre que même un gigantesque paquebot peut s'échouer sur un petit rocher, alors...
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 12h02   #18
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
J'ai essayé ça aussi :

Code :
List<categorie> data= catfacade.findAll();
la même erreur ressort.
Donc, j'en déduit que ce n'est peut être pas les arguments de la méthode find, mais peut-être bien le prblm de "public/private" indiqué dans mon post précédent ?
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 12h17   #19
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
c'est vrai que les attributs sont private avec des getter/setter public
je n'avais pas fait attention à ce détail.
dans ce que je fais, c'est le cas et l'annotation est placée sur le getter
Code :
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
 
@Entity
@Table(name = "LATABLE", schema = "SCHEMA")
public class Latable implements java.io.Serializable
{
    public static final long serialVersionUID = 1;
    private String ide01p;
    private String ini01p;
 
    public Latable()
    {
    }
 
    // Property accessors
    @Id
    @Column(name = "IDE01P", unique = true, nullable = false, length = 5)
    public String getIde01p()
    {
        return this.ide01p;
    }
 
    public void setIde01p(String ide01p)
    {
        this.ide01p = ide01p;
    }
 
    @Column(name = "INI01P", nullable = false, length = 10)
    public String getIni01p()
    {
        return this.ini01p;
    }
 
    public void setIni01p(String ini01p)
    {
        this.ini01p = ini01p;
    }
}
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 19h55   #20
Invité régulier
 
Homme Jean-michel DELFINO
Administrateur systèmes et réseaux
Inscription : janvier 2012
Messages : 27
Détails du profil
Informations personnelles :
Nom : Homme Jean-michel DELFINO
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : Associations - ONG

Informations forums :
Inscription : janvier 2012
Messages : 27
Points : 6
Points : 6
J'ai repris une web application à zéro, en suivant méticuleusement le tutoriel du supélec indiqué au début de cette discussion...

voici le code des pages principales :

Product.Java
Code :
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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;
 
import java.io.Serializable;
import javax.persistence.*;
 
@Entity
@Table(name="PRODUCT")
 
public class Product implements Serializable {
    @Column(name="ID") @Id private Integer ident;
    @Column(name="NAME") private String nom;
    @Column(name="SELLING_PRICE") private Integer prixVente;
 
public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
 
public void setIdent(Integer ident) {
       this.ident = ident; 
    }
    public Integer getIdent(){
        return ident;
    }
 
    public void setNom(String nom) {
       this.nom = nom; 
    }
    public String getNom(){
        return nom;
    }
 
    public void setPrixVente(Integer prixVente) {
       this.prixVente = prixVente; 
    }
    public Integer getPrixVente(){
        return prixVente;
    }    
 
}
CatalogManager.java
Code :
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
51
52
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;
 
import facade.ProductFacade;
import java.beans.*;
import javax.faces.bean.ApplicationScoped;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import model.Product;
 
@ManagedBean
@ApplicationScoped
@EJB
 
public class CatalogManager implements Serializable {
 
    private ProductFacade productfacade;
    private ArrayList<Product> arListProduct   ;
 
    public CatalogManager(){
        this.arListProduct = new ArrayList<Product>();
    }
 
        public void setArListProduct(ArrayList<Product> arListProduct) {
       this.arListProduct = arListProduct; 
    }
 
    public ArrayList<Product> getArListProduct(){
        return arListProduct;
 
    }
 
    public void setproductFacade(ProductFacade productfacade) {
       this.productfacade = productfacade; 
    }
    public ProductFacade getproductfacade(){
        return productfacade;
    }
 
        @PostConstruct
        public void initCatalog(){
        Product nouveau = new Product();
        nouveau=productfacade.find(1);
        this.arListProduct.add(nouveau);
}
}
persistence.xml
Code :
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="eMarketPU" transaction-type="JTA">
    <jta-data-source>jdbc/eMarket</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>
ProductFacade.java
Code :
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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;
 
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import model.Product;
 
/**
 *
 * @author jm
 */
@Stateless
public class ProductFacade extends AbstractFacade<Product> {
    @PersistenceContext(unitName = "eMarketPU")
    private EntityManager em;
 
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
 
    public ProductFacade() {
        super(Product.class);
    }
 
}
AbstractFacade.java
Code :
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
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;
 
import java.util.List;
import javax.persistence.EntityManager;
 
/**
 *
 * @author jm
 */
public abstract class AbstractFacade<T> {
    private Class<T> entityClass;
 
    public AbstractFacade(Class<T> entityClass) {
        this.entityClass = entityClass;
    }
 
    protected abstract EntityManager getEntityManager();
 
    public void create(T entity) {
        getEntityManager().persist(entity);
    }
 
    public void edit(T entity) {
        getEntityManager().merge(entity);
    }
 
    public void remove(T entity) {
        getEntityManager().remove(getEntityManager().merge(entity));
    }
 
    public T find(Object id) {
        return getEntityManager().find(entityClass, id);
    }
 
    public List<T> findAll() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        return getEntityManager().createQuery(cq).getResultList();
    }
 
    public List<T> findRange(int[] range) {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        javax.persistence.Query q = getEntityManager().createQuery(cq);
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        return q.getResultList();
    }
 
    public int count() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
        javax.persistence.Query q = getEntityManager().createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
 
}
dans Netbeans, je n'ai plus aucune erreur.
Mais à l'exécution, ça plante avec comme message :
Erreur lors de l?injection de ressources dans le bean géré «catalogManager»

Code :
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
com.sun.faces.mgbean.ManagedBeanCreationException: Erreur lors de l?injection de ressources dans le bean géré «catalogManager»
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99)
	at com.sun.el.parser.AstValue.getValue(AstValue.java:158)
	at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
	at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
	at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
	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:679)
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting invoke lifecycle  method public void logic.CatalogManager.initCatalog()
	at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:231)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
	... 55 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting invoke lifecycle  method public void logic.CatalogManager.initCatalog()
	at org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:393)
	at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:306)
	at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:229)
	... 56 more
Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
	at java.security.AccessController.doPrivileged(Native Method)
	at org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:376)
	... 58 more
Caused by: java.lang.reflect.InvocationTargetException
	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.faces.integration.GlassFishInjectionProvider$2.run(GlassFishInjectionProvider.java:382)
	... 60 more
Caused by: java.lang.NullPointerException
	at logic.CatalogManager.initCatalog(CatalogManager.java:49)
	... 65 more
Que faire ? SOS ! Faut vraiment que ça marche...
Où puis-je trouver, au pire, un petit exemple à télécharger qui fonctionne et qui pourrait me servir de modèle pour comprendre ?
jmdel5327 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h04.


 
 
 
 
Partenaires

Hébergement Web