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 :

No Such entity [EJB2.1 Entity]


Sujet :

Java EE

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8
    Points : 5
    Points
    5
    Par défaut No Such entity
    Bonjour,

    Voilà je dois développer une application et j'ai un gros problème que je ne comprend pas. J'aimerai via un EJB Session récuperer un EJB entité mais mon programme me lance à chaque fois une exception. Et je ne comprend pas d'où ca vient car en plus dans mon cours j'ai exactement le même type d'exemple.

    Mon 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
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    // On établit la connexion à l'EJB SessionEJBTraitementLabo
        try
        {
          context = getInitialContext("OC4J");  //  OC4J  ou J2EE
          Object objref = context.lookup("SessionEJBTraitementLabo");
     
          // Récupération de l'interface locale
          intLoc = (SessionEJBTraitementLaboHome)PortableRemoteObject.narrow(objref, SessionEJBTraitementLaboHome.class);
     
          // Convertit le champ texte du labo en numéro
          String tfNumlaboTemp = tfNumLabo.getText();
          int NumLabo = Integer.parseInt(tfNumlaboTemp);
          // Récupération de l'interface distante de l'EJB Session (grâce à l'interface locale)
          intDist = intLoc.create(tfLogin.getText(), tfPass.getText(), "Administratif", NumLabo);
        }
        catch(NamingException Erreur)
        {
          JOptionPane.showMessageDialog(null, Erreur, "Serveur pas trouvé (mauvais nom ?)", JOptionPane.ERROR_MESSAGE);
          return;
        }
        catch(Exception Erreur)
        {
          JOptionPane.showMessageDialog(null, Erreur, "Erreur lors de la connexion au serveur", JOptionPane.ERROR_MESSAGE);
          return;
        }
     
        // Si pas d'exception, Recherche
        try
        {
          JOptionPane.showMessageDialog(null, "Recherche des prescritions", "Debug", JOptionPane.ERROR_MESSAGE);
          // Efface tout le vecteur
          VPrescription.clear();
          JOptionPane.showMessageDialog(null, "Vecteur vidé", "Debug", JOptionPane.ERROR_MESSAGE);
          // Vérifie que l'utilisateur existe bien et retourne les prescriptions non encore validés
          VPrescription.addAll(intDist.getPrescriptionNonValide());
          JOptionPane.showMessageDialog(null, "getPrescriptionNonValide effectué", "Debug", JOptionPane.ERROR_MESSAGE);
        }
        catch(Throwable Erreur)
        {
          JOptionPane.showMessageDialog(null, Erreur, "Erreur sur le serveur !", JOptionPane.ERROR_MESSAGE);
        }
    Mon EJB Session:
    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
     
    // Méthode qui renvoit les prescriptions associées à un labo
      public Vector getPrescriptionNonValide() throws Exception
      {
        System.out.println("< SessionEJBTraitementLaboBean: getPrescriptionNonValide >");
     
        // Vérifie l'identité du client
        try
        {
          EntityEJBPersonnel e;
          // Appel l'EJB entité Personnel pour vérifier si le client existe bien
          e = getEJBEntityPersonnel();
        }
        catch(Exception Erreur)
        {
          throw new Exception("Erreur appel getEJBEntity dans getPrescriptionNonValide :: " + Erreur.getMessage());
        }
    }
     
    // Méthode privée pour récupérer l'EJB entité EntityEJBTraitementLabo
      private EntityEJBPersonnel getEJBEntityPersonnel() throws Exception
      {
        System.out.println("< SessionEJBTraitementLaboBean: getEJBEntityPersonnel >");
     
        try
        {
          // Cree le context de nom JNDI
          Context context = getInitialContext("OC4J");
          // Retrouve l'objet associé au nom JNDI
          Object objref = context.lookup("EntityEJBPersonnel");
          // Récupère l'interface locale
          EntityEJBPersonnelHome home = (EntityEJBPersonnelHome)PortableRemoteObject.narrow(objref, EntityEJBPersonnelHome.class);
          System.out.println("<DEBUG> SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: A recupéré l'interface locale (Personnel)");
     
          // Construit une clé primaire
          EntityEJBPersonnelPK key = new EntityEJBPersonnelPK(Login, Pass, AdminOrLabo, ID_LABO);
     
    // PLANTE ICI !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
    // --> return (EntityEJBPersonnel)home.findByPrimaryKey(key);
    // PLANTE ICI !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   
        }
        catch(NamingException Erreur)
        {
          System.out.println("!! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: NamingException !!");
          throw new Exception("Personnel non trouvé ! " + Erreur.getMessage());
        }
        catch(Exception Erreur)
        {
    // LANCE CETTE EXCEPTION A CHAQUE FOIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          System.out.println("!! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: Exception !!");
          throw new Exception("Exception dans getEJBEntityPersonnel :: " + Erreur.getMessage());
        }
      }
    Mon EJB entité
    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
     
    // Méthode de recherche de l'interface Home
      public EntityEJBPrescriptionPK ejbFindByPrimaryKey(EntityEJBPrescriptionPK key) throws FinderException
      {
        System.out.println("< EntityEJBPrescription: ejbFindByPrimaryKey >");
     
        String RequeteSQL = "SELECT * FROM Prescription WHERE ID_PRE = ?";
     
        ResultSet Resultat;
     
        try
        {
          PreparedStatement Requete = Connexion.prepareStatement(RequeteSQL);
          Requete.setInt(1, key.getPrescriptionID_PRE());
     
          Resultat = Requete.executeQuery();
          if(Resultat.next())
          {
            this.ID_PRE = key.getPrescriptionID_PRE();
            this.ID_MED = Resultat.getInt("ID_MED");
            this.ID_PAT = Resultat.getInt("ID_PAT");
            this.ID_LABO = Resultat.getInt("ID_LABO");
            this.Libelle = Resultat.getString("Libelle");
            this.NbrAnalyse = Resultat.getInt("NbrAnalyse");
            this.Valide = Resultat.getInt("Valide");
          }
          else
          {
            Connexion.close();
            throw new NoSuchEntityException("Serveur: " + key.getPrescriptionID_PRE()  + " introuvable !>");
          }
        }
        catch(SQLException Erreur)
        {
          throw new FinderException("ejbFindByPrimaryKey : " + Erreur.getMessage());
        }
        catch(EJBException Erreur)
        {
          System.out.println("!! EntityEJBPrescription: Connexion BD KO !!");
          throw new FinderException("Connexion BD KO " + Erreur.getMessage());
        }
     
        System.out.println("EntityEJBPrescription: ejbFindByPrimaryKey a trouvé :: " + key.getPrescriptionID_PRE());
     
        return key;
      }
    L'interface Home de mon ejb entité:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    public interface EntityEJBPersonnelHome extends EJBHome 
    {
      EntityEJBPersonnel create(String Login, String Pass, String AdminOrLabo, int ID_LABO, String Nom, String Prenom) throws RemoteException, CreateException;
      EntityEJBPersonnel findByPrimaryKey(EntityEJBPersonnelPK primaryKey) throws RemoteException, FinderException;
    }
    Aidez moi svp car je ne comprend pas du tout pq ca déconne car tous les exemples du même type que j'ai trouvé fonctionne de cette manière. Je n'ai aucune erreur de compilation et j'ai validé mes EJB et il n'y a aucune erreur non plus.

    Je développe avec JDeveloper 10g et je déplois avec OC4J

    Si qqun est motivé pour que je lui passe le code pour qu'il test avec un autre environement ca serait cool. Je serai fixé si c'est une erreur de code ou si c'est OC4J qui déconne

    Merci d'avance !

  2. #2
    Membre actif

    Inscrit en
    Mai 2002
    Messages
    328
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mai 2002
    Messages : 328
    Points : 209
    Points
    209
    Par défaut
    Quelle est l'exception ???

    Toine

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    L'exception lancée est

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
        catch(Exception Erreur) 
        { 
    // LANCE CETTE EXCEPTION A CHAQUE FOIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
          System.out.println("!! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: Exception !!"); 
          throw new Exception("Exception dans getEJBEntityPersonnel :: " + Erreur.getMessage()); 
        }
    Dans l'EJB Session

  4. #4
    Membre éprouvé

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    882
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2004
    Messages : 882
    Points : 948
    Points
    948
    Par défaut
    donne nous plutot la stack trace...??!!

    Sun Certified Business Component Developer
    Sun Certified Java Programmer
    --
    The definitive toolbox for GWT applications: gwt-toolbox
    My blog about Java and JEE: Benjamin's Blog

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Voilà, vu que j'ai modifié le code pour refaire des tests. Je vais donc reposter une partie du code

    Mon 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
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
     
      private void bLister_actionPerformed(ActionEvent e)
      {
        // On établit la connexion à l'EJB SessionEJBTraitementLabo
        try
        {
          context = getInitialContext("OC4J");  //  OC4J  ou J2EE
          Object objref = context.lookup("SessionEJBTraitementLabo");
     
          // Récupération de l'interface locale
          intLoc = (SessionEJBTraitementLaboHome)PortableRemoteObject.narrow(objref, SessionEJBTraitementLaboHome.class);
     
          // Convertit le champ texte du labo en numéro
          String tfNumlaboTemp = tfNumLabo.getText();
          int NumLabo = Integer.parseInt(tfNumlaboTemp);
          // Récupération de l'interface distante de l'EJB Session (grâce à l'interface locale)
          intDist = intLoc.create(tfLogin.getText(), tfPass.getText(), "Administratif", NumLabo);
        }
        catch(NamingException Erreur)
        {
          JOptionPane.showMessageDialog(null, Erreur, "Serveur pas trouvé (mauvais nom ?)", JOptionPane.ERROR_MESSAGE);
          return;
        }
        catch(Exception Erreur)
        {
          JOptionPane.showMessageDialog(null, Erreur, "Erreur lors de la connexion au serveur", JOptionPane.ERROR_MESSAGE);
          return;
        }
     
    (...)
     
    }
    Mon ejb Session:
    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 Vector getPrescriptionNonValide() throws Exception
      {
        System.out.println("< SessionEJBTraitementLaboBean: getPrescriptionNonValide >");
     
        // Vérifie l'identité du client
        try
        {
          // Cree le context de nom JNDI
          Context context = getInitialContext("OC4J");
          // Retrouve l'objet associé au nom JNDI
          Object objref = context.lookup("EntityEJBPersonnel");
          // Récupère l'interface locale
          EntityEJBPersonnelHome home = (EntityEJBPersonnelHome)PortableRemoteObject.narrow(objref, EntityEJBPersonnelHome.class);
          System.out.println("<DEBUG> SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: A recupéré l'interface locale (Personnel)");
     
          // Construit une clé primaire
          EntityEJBPersonnelPK key = new EntityEJBPersonnelPK(Login, Pass, AdminOrLabo, ID_LABO);
     
    // PLANTE ICI !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
          EntityEJBPersonnel e = (EntityEJBPersonnel)home.findByPrimaryKey(key);
        }
        catch(NamingException Erreur)
        {
          System.out.println("!! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: NamingException !!");
          throw new Exception("Personnel non trouvé ! " + Erreur.getMessage());
        }
        catch(Exception Erreur)
        {
          System.out.println("!! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: Exception !!");
          throw new Exception("Exception dans getEJBEntityPersonnel :: " + Erreur.getMessage());
        }
        // Si pas d'erreur alors c'est que le client existe bien dans la BD
        System.out.println("<DEBUG> SessionEJBTraitementLaboBean: getPrescriptionNonValide :: Personnel retrouvé >");
     
    (...)
    Mon ejb entité:
    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 EntityEJBPersonnelPK ejbFindByPrimaryKey(EntityEJBPersonnelPK primaryKey) throws FinderException
      {
        System.out.println("< EntityEJBPersonnelBean: ejbFindByPrimaryKey >");
     
        String RequeteSQL = "SELECT * FROM Personnel WHERE Login = ? AND Pass = ? AND AdminOrLabo = ? AND ID_LABO = ?";
     
        ResultSet Resultat;
     
        try
        {
          PreparedStatement Requete = Connexion.prepareStatement(RequeteSQL);
          Requete.setString(1, primaryKey.getPersonnelLogin());
          Requete.setString(2, primaryKey.getPersonnelPass());     
          if(primaryKey.getPersonnelAdminOrLabo().equals("Administratif"))
          {
            Requete.setInt(3, 0);
          }
          else if(primaryKey.getPersonnelAdminOrLabo().equals("Laborantin"))
          {
            Requete.setInt(3, 1);
          }
          else 
          {
            Connexion.close();
            throw new NoSuchEntityException("Serveur: " + primaryKey  + " invalide !>");
          }
          Requete.setInt(4, primaryKey.getPersonnelID_LABO());
     
          Resultat = Requete.executeQuery();
          if(Resultat.next())
          {
            this.Login = primaryKey.getPersonnelLogin();
            this.Pass = primaryKey.getPersonnelPass();
            this.AdminOrLabo = primaryKey.getPersonnelAdminOrLabo();
            this.ID_LABO = primaryKey.getPersonnelID_LABO();
            this.Nom = Resultat.getString("Nom");
            this.Prenom = Resultat.getString("Prenom");
          }
          else
          {
            Connexion.close();
            throw new NoSuchEntityException("Serveur: " + primaryKey  + " introuvable !>");
          }
          Resultat.close();
        }
        catch(SQLException Erreur)
        {
          throw new FinderException("ejbFindByPrimaryKey : " + Erreur.getMessage());
        }
        catch(EJBException Erreur)
        {
          System.out.println("!! EntityEJBPersonnelBean: ejbFindByPrimaryKey :: Connexion BD KO : " + Erreur.getMessage() + " !!");
          throw new FinderException("Connexion BD KO " + Erreur.getMessage());
        }
     
        System.out.println("<DEBUG> EntityEJBPersonnelBean: ejbFindByPrimaryKey :: a trouvé : " + primaryKey);
     
        return primaryKey;
      }
    Et enfin voilà le résultat obtenu:
    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
     
    05/01/05 21:59:53 < SessionEJBTraitementLaboBean: setSessionContext >
    05/01/05 21:59:53 < SessionEJBTraitementLaboBean: ejbCreate >
    05/01/05 22:00:16 < SessionEJBTraitementLaboBean: getPrescriptionNonValide >
    05/01/05 22:00:16 < SessionEJBTraitementLaboBean: getInitialContext >
    05/01/05 22:00:16 <DEBUG> SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: A recupéré l'interface locale (Personnel)
    05/01/05 22:00:16 < EntityEJBPersonnelBean: setEntityContext >
    05/01/05 22:00:16 <DEBUG> EntityEJBPersonnelBean: setEntityContext :: Tentative de connexion à la base de données
    05/01/05 22:00:21 <DEBUG> EntityEJBPersonnelBean: setEntityContext :: Connexion à la base de données effectuée
    05/01/05 22:00:21 < EntityEJBPersonnelBean: ejbFindByPrimaryKey >
    05/01/05 22:00:21 <DEBUG> EntityEJBPersonnelBean: ejbFindByPrimaryKey :: a trouvé : admin1.admin1.Administratif.2
    05/01/05 22:00:21 < EntityEJBPersonnelBean: ejbActivate >
    05/01/05 22:00:21 < EntityEJBPersonnelBean: ejbLoad >
    05/01/05 22:00:21 < EntityEJBPersonnelBean: ejbPassivate >
    05/01/05 22:00:21 !! SessionEJBTraitementLaboBean: getEJBEntityPersonnel :: Exception !!
    05/01/05 22:03:08 < EntityEJBPersonnelBean: unsetEntityContext >
    Voilà, mon client affiche une message box qui dit
    "java.lang.Exception: Exception dans getEJBEntityPersonnel :: No Such entity: admin1. admin1.Administratif.2"

    (En sachant que admin1. admin1.Administratif.2 sont les valeur que ma clé primaire que je cherche avec mon findbyprimarykey)

    Une idée ??? Merci d'avance

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Voilà, apres de grosses recherches, j'ai enfin trouvé d'où provenait l'erreur.

    En fait lors de mon find, j'utilisait un preparedstatement et j'avais oublié de le fermer avec close() à la fin de son utilisation. Du coup lorsque mon EJB voulait utiliser sa méthode ejbLoad, il disait qu'une autre source était déjà en train d'utiliser la BD.

    Bref, je ne m'en suis pas rendu compte plus tot car mon exception ne relancait pas un message explicite.

    J'espere que mon erreur (maintenant résolue) poura aider qqun qui a le même genre d'erreur

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Pb JBOSS : No such entity!
    Par msadoq dans le forum Wildfly/JBoss
    Réponses: 0
    Dernier message: 20/04/2009, 10h57
  2. JBOSS javax.ejb.ObjectNotFoundException: No such entity!
    Par msadoq dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 17/04/2009, 11h33
  3. [Eclipse / Jonas] Erreur "jonas-entity missing for bean"
    Par citygirl dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 16/05/2005, 11h59
  4. Qt::connect: no such slot ...
    Par fdrouhin dans le forum Qt
    Réponses: 8
    Dernier message: 02/12/2004, 19h11
  5. [ Entity bean ] CMP
    Par hocinema dans le forum Websphere
    Réponses: 5
    Dernier message: 03/10/2003, 11h33

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