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 :

Erreur DAo Ejb session


Sujet :

Java EE

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé

    Inscrit en
    Avril 2005
    Messages
    246
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 246
    Par défaut Erreur DAo Ejb session
    Bonjour,

    J'ai une erreur que je ne comprends pas apres avoir developpé un ejb session avec le pattern DAO :

    5:48:43,658 ERROR [LogInterceptor] RuntimeException in method: public abstract java.lang.String com.access.interfaces.EzbayAccess.loginUser(java.lang.String,java.lang.String) throws java.rmi.RemoteException:
    java.lang.ClassCastException: com.ezbay.dao.EzbayAccessDAOImp
    at com.access.ejb.EzbayAccessSession.getDao(EzbayAccessSession.java:51)
    at com.access.ejb.EzbayAccessSession.loginUser(EzbayAccessSession.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
    at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
    at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
    at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
    at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
    at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
    at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
    at org.jboss.ejb.Container.invoke(Container.java:873)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
    at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
    at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
    Lorsque je fais cet appel :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    protected static synchronized com.access.dao.EzbayAccessDAO getDao()
       {
          if (dao != null) {
             return dao;
          } else {
     
             dao = (com.access.dao.EzbayAccessDAO) new com.ezbay.dao.EzbayAccessDAOImp();
     
             dao.init();
             return dao;
          }
    Quelqu'un peut-il m'aider?

    Merci

  2. #2
    Membre éprouvé
    Inscrit en
    Mai 2003
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 103
    Par défaut
    est ce que com.ezbay.dao.EzbayAccessDAOImp implemente ou etend bien la classe om.access.dao.EzbayAccessDAO ?

    a part cela, tu retournes pas ton impl de ta DAO au client EJB ?

  3. #3
    Membre Expert
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Par défaut
    Donne nous les déclarations des interfaces Home et Remote ainsi que la déclaration de ton EJB stp

  4. #4
    Membre éclairé

    Inscrit en
    Avril 2005
    Messages
    246
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 246
    Par défaut
    Merci pour vos réponses

    1) com.ezbay.dao.EzbayAccessDAOImp implemente la classe om.access.dao.EzbayAccessDAO

    2) Voici les interfaces

    EzbayAccessLocalHome :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public interface EzbayAccessLocalHome
       extends javax.ejb.EJBLocalHome
    {
       public static final String COMP_NAME="java:comp/env/ejb/EzbayAccessLocal";
       public static final String JNDI_NAME="EzbayAccessLocal";
     
       public com.access.interfaces.EzbayAccessLocal create()
          throws javax.ejb.CreateException;
     
    }
    EzbayAccessHome:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public interface EzbayAccessHome
       extends javax.ejb.EJBHome
    {
       public static final String COMP_NAME="java:comp/env/ejb/EzbayAccess";
       public static final String JNDI_NAME="ejb/EzbayAccess";
     
       public com.access.interfaces.EzbayAccess create()
          throws javax.ejb.CreateException,java.rmi.RemoteException;
     
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public interface EzbayAccessDAO
    {
        public void init();
     
        public java.lang.String loginUser(java.lang.String userNom,java.lang.String motDePasse) ;
     
    }
    l'ejb:
    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
     
    /**
     * @ejb.bean name="EzbayAccess" 
     * display-name="Name for EzbayAccess"
     *           description="Description for EzbayAccess"
     *           jndi-name="ejb/EzbayAccess" 
     *           type="Stateless" 
     *           view-type="both"
     * 
     
     * @ejb.dao class="com.access.dao.EzbayAccessDAO" 
     *     impl-class="com.access.dao.EzbayAccessDAOImp" 
     * 
     * 
     * @ejb.resource-ref res-ref-name="jdbc/MySqlDS" 
     * res-type="javax.sql.DataSource" 
     * res-auth="Container" 
     * 
     * 
     * @jboss.resource-ref res-ref-name="jdbc/MySqlDS" 
     * jndi-name="java:/MySqlDS" 
     * 
     
     */
    public class EzbayAccess implements SessionBean {
     
    	private SessionContext context;
     
    	public EzbayAccess() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    /**
     * @ejb.interface-method
     * view-type="remote"
     * @dao.call name="loginUser"
     */
    	public String loginUser(String userNom, String motDePasse){
    		System.out.println("Entering EzbayAccess");
    			System.out.println("Leaving EzbayAccess");
    			return null;
    	}

  5. #5
    Membre éprouvé
    Inscrit en
    Mai 2003
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 103
    Par défaut
    dans ton descripteur EJB tu dis que l'impl c'est
    com.access.dao.EzbayAccessDAOImp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    * @ejb.dao class="com.access.dao.EzbayAccessDAO"
     *     impl-class="com.access.dao.EzbayAccessDAOImp"
    et

    dans le code tu fais un new com.ezbay.dao.EzbayAccessDAOImp();

    c'est peu etre juste ?

  6. #6
    Membre éclairé

    Inscrit en
    Avril 2005
    Messages
    246
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 246
    Par défaut
    Bonjour,

    Effectivement, j'ai modifié en mettant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    * @ejb.dao class="com.access.dao.EzbayAccessDAO" 
     *     impl-class="com.ezbay.dao.EzbayAccessDAOImp"
    mais j'ai toutjours la même erreur

  7. #7
    Membre éprouvé
    Inscrit en
    Mai 2003
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 103
    Par défaut
    est que l'erreur vient bien de la ligne du cast dans ton bout de code de la methode com.access.dao.EzbayAccessDAO getDao() ?

    tu peux mettre le code de l'Imp ?

    encore un point , tu aurais pas plusieurs fois ta classe dans ton appli ? une fois dans une lib, une fois dans le war ? à tout hasard

  8. #8
    Membre éclairé

    Inscrit en
    Avril 2005
    Messages
    246
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 246
    Par défaut
    voici le code de l'imp:


    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
     
    package com.ezbay.dao;
     
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
     
    import javax.ejb.EJBException;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
     
    public class EzbayAccessDAOImp implements EzbayAccessDAO {
     
    	private DataSource dataSource;
     
    	public void init() {
    		InitialContext initialContext = null;
    		if (dataSource == null)
    		{
    			try
    			{
    				initialContext = new InitialContext();
    				this.dataSource = (DataSource) initialContext
    						.lookup("java:/jdbc/MySqlDS");
    			} catch (NamingException e)
    			{
    				e.printStackTrace();
    			}
    		}
     
    	}
     
    	public String loginUser(String username, String password) throws EJBException {
     
    		String userId = null;
    		Connection connection = null;
    		PreparedStatement ps = null;
    		ResultSet rs = null;
    		try
    		{
    			connection = dataSource.getConnection();
    			String sql = "select userid from jboss where username = ? and password = ?";
    			ps = connection.prepareStatement(sql);
    			ps.setString(1, username);
    			ps.setString(2, password);
    			rs = ps.executeQuery();
    			if (rs.next())
    				userId = rs.getString(1);
     
    		} catch (SQLException e)
    		{
    			// do nothing, we will return null
    			e.printStackTrace();
    		} finally
    		{
    			try
    			{
    				ps.close();
    				rs.close();
    				connection.close();
    			} catch (SQLException e)
    			{
     
    			}
    		}
    		return userId;
    	}
     
    }

  9. #9
    Membre éprouvé
    Inscrit en
    Mai 2003
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 103
    Par défaut
    a voir le bout de code, la classe
    EzbayAccessDAOImp implements EzbayAccessDAO mais il n'y a pas d'import du package com.access.dao donc si cela compile tu as une interface EzbayAccessDAO dans le package courant com.ezbay.dao . donc problème de cast .

    puisque tu déclares
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    * @ejb.dao class="com.access.dao.EzbayAccessDAO"
     *     impl-class="com.ezbay.dao.EzbayAccessDAOImp"

    ou alors un problème du copier coller dans cettte page

Discussions similaires

  1. Réponses: 3
    Dernier message: 19/01/2013, 13h33
  2. Réponses: 4
    Dernier message: 17/03/2006, 18h39
  3. [EJB][Jboss] problème de déploiment d'EJB session
    Par 17mounir dans le forum Wildfly/JBoss
    Réponses: 1
    Dernier message: 13/03/2006, 01h16
  4. [EJB Session] class not found exception ?
    Par champion dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 11/02/2005, 23h46
  5. [Débutant] [lomboz] EJB Session
    Par VinceFromBcn dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 19/01/2005, 19h51

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