IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java EE Discussion :

Problème avec l'interface locale d'un bean


Sujet :

Java EE

  1. #1
    Débutant
    Inscrit en
    Février 2003
    Messages
    54
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 54
    Points : 35
    Points
    35
    Par défaut Problème avec l'interface locale d'un bean
    Je travaille sur un projet d'ejb. Le code suivant fonctionne :

    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
     
    public class TestStudent {
    	Properties properties;
    	public TestStudent() {
    		properties = new Properties();
    		properties.put("java.naming.factory.initial",
    		"org.jnp.interfaces.NamingContextFactory");
    		properties.put("java.naming.factory.url.pkgs",
    		"org.jboss.naming:org.jnp.interfaces");
    		properties.put("java.naming.provider.url", "jnp://localhost:1099");
    		properties.put("jnp.disableDiscovery", "true");
    	}
     
    	public static void main(String[] args) {
    		TestStudent beanStudent = new TestStudent();
    		beanStudent.createBean();
    	}
    	public void createBean() throws EJBException {
    		try {
    			InitialContext context = new InitialContext(properties);
     
    			Object object = context.lookup(StudentHome.JNDI_NAME);
    			StudentHome studentHome = (StudentHome) PortableRemoteObject.narrow(object,StudentHome.class);
    			Student student = studentHome.create();
    			student.setName("pirlouit");
    			System.out.println(student.getId());
    			System.out.println(student.getName());
    		} catch (NamingException e) {
    			throw new EJBException(e);
    		} catch (RemoteException e) {
    			throw new EJBException(e);
    		} catch (CreateException e) {
    			throw new EJBException(e);
    		}
    	}
    }
    alors que le code suiant, utilisant l'interface locale du bean ne fonctionne pas :

    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
     
    public class TestStudent {
    	Properties properties;
    	public TestStudent() {
    		properties = new Properties();
    		properties.put("java.naming.factory.initial",
    		"org.jnp.interfaces.NamingContextFactory");
    		properties.put("java.naming.factory.url.pkgs",
    		"org.jboss.naming:org.jnp.interfaces");
    		properties.put("java.naming.provider.url", "jnp://localhost:1099");
    		properties.put("jnp.disableDiscovery", "true");
    	}
     
    	public static void main(String[] args) {
    		TestStudent beanStudent = new TestStudent();
    		beanStudent.createBean();
    	}
    	public void createBean() throws EJBException {
    		try {
    			InitialContext context = new InitialContext(properties);
     
    			Object object = context.lookup(StudentLocalHome.JNDI_NAME);
    			StudentLocalHome studentLocalHome = (StudentLocalHome)object;
    			System.out.println("studentLocalHome is null ? "+studentHome.equals(null));
    			StudentLocal student = studentLocalHome.create();
    			student.setName("pirlouit");
    			System.out.println(student.getId());
    			System.out.println(student.getName());
    		} catch (NamingException e) {
    			throw new EJBException(e);
    		} /*catch (RemoteException e) {
    			throw new EJBException(e);
    		}*/ catch (CreateException e) {
    			throw new EJBException(e);
    		}
    	}
    }
    L'affichage me donne true, ce qui signifie que l'objet studentLocalHome est null (là est le problème ...)

    qqn sait il ce qui ne va pas dans mon code ?

    Merci d'avance

  2. #2
    Membre habitué
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2005
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2005
    Messages : 63
    Points : 163
    Points
    163
    Par défaut
    Est ce que l'on pourrait voir ton ejb-jar.xml ?

    Ta classe TestStudent fait partie d'un projet ejb ? d'un projet web ?

    Il faut que tu déclares une référence vers ton ejb pour pouvoir accéder à celui-ci en local.

  3. #3
    Débutant
    Inscrit en
    Février 2003
    Messages
    54
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 54
    Points : 35
    Points
    35
    Par défaut
    j'ai compris en fait que pour accéd à mon bean entité par son interface locale, je devais passer par un bean session (en facade). C'est bien ca qu'il faut faire ?

    En ce qui concernet la classe TestStudent, elle fait partie du projet ejb.

    Merci de ton aide, c'est gentil, mais à priori ca va marcher avec la session en facade. J'avais mal compris la différence entre local et distant.

Discussions similaires

  1. énorme problème avec mon interface MFC
    Par cenedra dans le forum MFC
    Réponses: 23
    Dernier message: 17/07/2006, 09h36
  2. énorme problème avec mon interface MFC
    Par cenedra dans le forum C++
    Réponses: 2
    Dernier message: 12/07/2006, 09h54
  3. Problème avec deux interfaces
    Par ikeaboy dans le forum Langage
    Réponses: 2
    Dernier message: 28/05/2006, 14h56
  4. problème avec le disque local
    Par suiss dans le forum Windows XP
    Réponses: 16
    Dernier message: 30/11/2005, 23h11
  5. problème avec load data local
    Par afrikha dans le forum Débuter
    Réponses: 2
    Dernier message: 28/10/2005, 18h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo