Bonjour!
Je débute dans les EJB3. Je viens de faire une classe Entity très simple pour accéder à une table dans la base de données.
J'ai un Bean session pour accéder à cet Entity.
Et enfin, j'ai un client externe pour tester tout ça. Le serveur d'appli est Jonas (et tout se déploie bien).
Le problème, c'est que quand je lance le client, il me sort l'erreur :
Voici les classes en question (tronquées):Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.CPESessionBean
at src.CPEHelloClient.main(CPEHelloClient.java:26)
Et le client :
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 @Remote(CPESessionInterface.class) public class CPESessionBean implements CPESessionInterface { @PersistenceContext(name="CPEPersistenceContext") private EntityManager em; @EJB CPEBean cpe; public void addCPE(String OUI, String Constructor, String Serial) { cpe = new CPEBean(); cpe.setConstructor(Constructor); cpe.setOUI(OUI); cpe.setSerial(Serial); em.persist(cpe); } }
Donc là je n'ai plus trop d'idée... je pense que le problème vient du client, mais je ne peux pas en être sûr...
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 public class CPEHelloClient { public static void main(String[] args) { Hashtable<String, String> h = new Hashtable<String, String>(); h.put("java.naming.factory.initial","org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); h.put("java.naming.provider.url","rmi://localhost:1099"); h.put("java.naming.factory.url.pkgs", "org.objectweb.jonas.naming"); /*InitialContext context = new InitialContext(); ConnectionManager dataSource = (ConnectionManager)context.lookup("java:comp/env/jdbc/clientDB"+source);*/ String JNDI_NAME = "com.CPESessionBean" + "_" + CPESessionInterface.class.getName() + "@Remote"; try { InitialContext context = new InitialContext(h); System.out.println("lookup " + JNDI_NAME); CPESessionBean beanRemote = (CPESessionBean) context.lookup(JNDI_NAME); beanRemote.addCPE("OhOUIAlors", "Builder", "Serialz"); System.out.println(beanRemote.findByOUI("OUI")); } catch (NamingException e) { e.printStackTrace(); e.getRootCause(); } } }
Merci d'avance pour votre aide!
Partager