Bonjour,

Je veux développer un petit répertoire en utilisant un ejb session bean.

j'ai une interface NewSessionRemote :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
@Remote
public interface NewSessionRemote {
 
    public void addPerson(Personne unePersonne) throws Exception;
    public void updatePerson(Personne unePersonne) throws Exception;
    public void removePerson (Personne unePersonne)throws Exception;
    public void searchPerson(String name)throws Exception;
}
j'ai une classe implémentant cette interface :

prenons le cas de l'ajout par exemple :

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
@Stateful
public class NewSessionBean implements NewSessionRemote {
 
    ArrayList<Personne> list= new ArrayList<Personne>();
 
    public void addPerson(Personne unePersonne)throws Exception {
        try
        {
            list.add(unePersonne);
        }
        catch (UnsupportedOperationException ex)
        {
            ex.toString();
        }
    }
 
 
}
voilà à quoi ressemble ma classe personne :
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
51
52
53
54
55
56
57
58
59
60
public class Personne implements Serializable   {
 
 private static final long serialVersionUID = 42L;
 
    String nom;
    String prenom;
    String adresse;
    String ville;
    int cp;
    String numTel;
 
    // default constructor
    public Personne(){}
 
    public Personne (String pNom, String pPrenom, String pAdresse, String pVille, int pCp, String numTel){
        this.nom=pNom;
        this.prenom=pPrenom;
        this.adresse=pAdresse;
        this.ville=pVille;
        this.cp=pCp;
        this.numTel=numTel;
    }
 
    public String getNom(){
        return nom;
    }
    public void setNom(String pNom){
        this.nom=pNom;
    }
    public String getPrenom(){
        return prenom;
    }
    public void setPrenom(String pPrenom){
        this.prenom=pPrenom;
    }
    public String getAdresse(){
        return adresse;
    }
    public void setAdresse(String pAdresse){
        this.adresse=pAdresse;
    }
    public String getVille(){
        return ville;
    }
    public void setString(String pVil){
        ville=pVil;
    }
    public int getCp(){
        return cp;
    }
    public void setCp(int pCp){
        this.cp=pCp;
    }
    public String getNumTel (){
        return numTel;
    }
    public void setNumTel(String pNum){
        this.numTel=pNum;
    }
}
ensuite j'ai crée une petite ihm côté client pour invoquer l'ejb avec un bouton "ajouter" pour ajouter une personne

voici le code du bouton :

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
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 
 
        Personne unePersonne=new Personne(jTextField2.getText(), jTextField3.getText(),
                jTextField4.getText(), jTextField5.getText(), Integer.parseInt(jTextField6.getText()),jTextField7.getText());
        try {
 
            // proprietes de connexion
            Hashtable environment = new Hashtable();
            environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
 
            // initialisation du contexte
            InitialContext context = new InitialContext(environment);
 
            // récupération du contexte
            NewSessionRemote beanRemote =(NewSessionRemote) context.lookup("NewSessionBean/remote");
 
            try {
                beanRemote.addPerson(unePersonne);
                System.out.println("la personne est ajoutée");
 
            } catch (Exception ex) {
                Logger.getLogger(Repertoire.class.getName()).log(Level.INFO, null, ex);
            }
            } catch (NamingException nEx) {
                Logger.getLogger(Repertoire.class.getName()).log(Level.INFO, null, nEx);
            }
 
    }
qd je déploie mon ejb j'ai l'erreur suivante :
java.lang.RuntimeException: java.io.InvalidClassException: bo.Personne; class invalid for deserialization
Je ne comprends pas d'où provient l'erreur et je débute avec les ejb j'en appelle donc à vos lumières

merci d'avance

bilou69