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 :

Connexion à un EJB statefull


Sujet :

Java EE

  1. #1
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut Connexion à un EJB statefull
    Bonjour à tous ,alors voilà j'essaye de me connecter à mon ejb statefull lors de l'utilisation de ma fonction:

    J'ai l'erreur suivante ;

    Code JAVA : 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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    Exception in thread "AWT-EventQueue-1" javax.ejb.EJBException: java.lang.IllegalStateException: JBAS014366: Session id hasn't been set for stateful component: AmortissementAvecEtat
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:43)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    	at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
    	at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:302)
    	at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$200(MethodInvocationMessageHandler.java:64)
    	at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:196)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    	at org.jboss.threads.JBossThread.run(JBossThread.java:122)
    	at ...asynchronous invocation...(Unknown Source)
    	at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:99)
    	at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:270)
    	at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47)
    	at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:272)
    	at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:132)
    	at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:260)
    	at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:399)
    	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:140)
    	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    	at $Proxy0.calculerAmortissement(Unknown Source)
    	at client.Amortissement.conserver(Amortissement.java:237)
    	at client.Amortissement$3.actionPerformed(Amortissement.java:180)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

    Voici ma fonction qui récupère la connexion :

    Code JAVA : 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
      public void conserver(int Somme,int Date,int annee,int duree,int taux) {
    		// TODO Auto-generated method stub
    		// Appel du stateless bean
            AmortissementAvecEtatRemote Amortissement;
    		try {
    			Amortissement = lookupRemoteStatelessAvecEtatAmortissement();
    		 Amortissement.calculerAmortissement( Somme, Date, annee, duree, taux);
    		 Object[][] donnee = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
    	        String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
    	        JTable table = new JTable( donnee,entetes);
    	        table.size();
    	 	table.setBounds(116, 240, 300,300);
    	        getContentPane().add(table);
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}
    Ma fonction de connexion :

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     // Connexion au serveur et lookup du bean
        private static AmortissementAvecEtatRemote lookupRemoteStatelessAvecEtatAmortissement() throws NamingException {
        	AmortissementAvecEtatRemote remote=null;
          try {
              Properties jndiProps = new Properties();
              jndiProps.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
              InitialContext ctx = new InitialContext(jndiProps); 
              remote = (AmortissementAvecEtatRemote) ctx.lookup("ejb:/AmortissementEJB/AmortissementAvecEtat!hw.AmortissementAvecEtatRemote");
          	} catch (Exception e) {
              e.printStackTrace();
          		}    	
          return  remote;
      }

    et voici mon ejb :

    Code JAVA : 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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    package hw;
     
     
     
    import java.util.ArrayList;
     
    import javax.ejb.LocalBean;
    import javax.ejb.Stateful;
     
    /**
     * Session Bean implementation class Amortissement
     */
     
    @Stateful
    public class AmortissementAvecEtat implements AmortissementAvecEtatRemote {
    	private ArrayList<Object[][]> buffer = new ArrayList<Object[][]>();
        /**
         * Default constructor. 
         */
        public AmortissementAvecEtat() {
            // TODO Auto-generated constructor stub
        }
     
        public Object [][] calculerAmortissement(int somEmprunt,  int moisDebut,
    			int anneeDebut, int dureePret, int tauxAnnuel) {
    		// CALCUL DE L'AMORTISSEMENT
    		double tauxMensuel = ((double)tauxAnnuel / 12) / 100;
    		int dureeMensuelPret = dureePret * 12;
    		int capitalRestantDu = somEmprunt;
    		int moisPeriode = moisDebut;
    		int anneePeriode = anneeDebut;
    		int amortissementPeriode = 0;
    		int interetsPeriode = 0;
    		int mensualiteConstante = (int) Math.round((((double)(somEmprunt * tauxMensuel)) / 
    				((double)(1 - Math.pow(1 + tauxMensuel, -dureeMensuelPret)))));
    		/* tableauAmortissement [...][0] : mois de la période
    		 * tableauAmortissement [...][1] : année de la période
    		 * tableauAmortissement [...][2] : mensualité
    		 * tableauAmortissement [...][3] : amortissement
    		 * tableauAmortissement [...][4] : intérêts
    		 */
    		Object [][] tableauAmortissement = new Object [dureeMensuelPret][5];
     
    		for (int i = 0; i < dureeMensuelPret; i++) {
    			interetsPeriode = (int) (capitalRestantDu * tauxMensuel);
    			amortissementPeriode = mensualiteConstante - interetsPeriode;
     
    			tableauAmortissement [i][0] = moisPeriode;
    			tableauAmortissement [i][1] = anneePeriode;
    			tableauAmortissement [i][2] = mensualiteConstante;
    			tableauAmortissement [i][3] = amortissementPeriode;
    			tableauAmortissement [i][4] = interetsPeriode;
     
    			capitalRestantDu = capitalRestantDu - amortissementPeriode;
     
    			moisPeriode++;
    			if (moisPeriode == 13) {
    				moisPeriode = 1;
    				anneePeriode++;
    			}
    		}
    		 this.buffer.add(tableauAmortissement);
    		return tableauAmortissement;
    		}
     
     
     
     
     
     
    	public ArrayList<Object[][]> getBuffer() {
    		return buffer;
    	}
     
    	public void setBuffer(ArrayList<Object[][]> buffer) {
    		this.buffer = buffer;
    	}
     
     
     
    }

    Merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    rajoute "?stateful" à la fin de la String servant au lookup.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
              remote = (AmortissementAvecEtatRemote) ctx.lookup("ejb:/AmortissementEJB/AmortissementAvecEtat!hw.AmortissementAvecEtatRemote?stateful");

  3. #3
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Super sa fonctionne merci beaucoup.

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

Discussions similaires

  1. Session EJB Statefull
    Par abdelhadi008 dans le forum Java EE
    Réponses: 0
    Dernier message: 17/11/2011, 02h32
  2. mesurer le Débit d'une connexion avec EJB
    Par EJB_Problem dans le forum Java EE
    Réponses: 0
    Dernier message: 12/04/2011, 17h00
  3. EJB Statefull et accès bdd
    Par aya19742007 dans le forum Persistance des données
    Réponses: 1
    Dernier message: 31/08/2010, 14h56
  4. Mise en place Connexion Mysql + EJB 3 + Hibernate
    Par Thomshao dans le forum Glassfish et Payara
    Réponses: 3
    Dernier message: 01/12/2008, 19h21
  5. [EJB]JBoss et Pool de connexion
    Par Kleb dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 20/04/2004, 12h12

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