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 de Création de L'entity Manager dans la DAO pour tester Mon EJB


Sujet :

Java EE

  1. #1
    Membre confirmé Avatar de bruneltouopi
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2010
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

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

    Informations forums :
    Inscription : Janvier 2010
    Messages : 308
    Points : 466
    Points
    466
    Par défaut Problème de Création de L'entity Manager dans la DAO pour tester Mon EJB
    Voilà j'utilise Maven pour compiler et assembler mes projets.J'ai crée un projet de type application pour gerer mon modèle qui contient mes entités puis ma DAO pour des opérations directes à la Base de données.
    Dans le premier temps j'ai utilisé le type de transaction RESOURCE_LOCAL dans mon fichier de persistence.xml et j'ai testé toutes mes DAO avec success.
    En passant comme on le sait je créait mon Entity manager grace à mon EntityManagerFactory.

    Dès lors je suis monté d'une couche et j'ai crée un autre projet Maven de type EJB et j'ai ajouté la dépendance avec le projet Dao.
    Dans le fichier de persistance mon type de transaction est désormais en JTA et dans ma DAO je n'utilise plus EntityManagerFactory,mais plutot
    @PersistenceContext
    .

    j'ai donc créer mon EJB et le souci est que en appellant mes méthodes de la DAO il me ressort l'entity manager null.

    Je précise que je peux manipulier directement mes entités avec
    @PersistenceContext
    dans mon EJB et cela marche.

    J'ai utilisé pour pouvoir tester mon EJB glassfish embedded.donc j'ai crée tout ce qu'il faut pool de connexion,JNDI BD.Seul souci pas d'access à la DAO.
    Et comme il me semble correct j'ai aussi supprimé tous les fichiers de persistence.xml qui étaient dans la DAO.
    ET ça marche toujours pas.Passons au Code
    Voici ma classe AbstractDAO qui partage les méthodes de toutes les entités et le pattern DAO exécute déjà le CRUD.cette classe est dans le projet DAO
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
     
    package org.better.dao;
     
     
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    import javax.persistence.*;
    import javax.persistence.criteria.CriteriaQuery;
    import javax.persistence.criteria.Root;
    import org.better.modele.DAOEntry;
     
    // CLASSE ABSTRAITE PERMETTANT DE MANIPULER L INTERFACE DAO
     
    public abstract class AbstractJpaDAO<T extends DAOEntry> implements DAO<T> {
     
        private static final long serialVersionUID = 1L;
     
     
        @PersistenceContext(name="Globalschool_PU")
        private EntityManager em;
     
     
     
     
        protected EntityManager getEntityManager() {
            return em;
        }
     
     
        protected AbstractJpaDAO() {
        }
     
        /**
         * @return The type of the class of the entity to work with.
         */
        protected abstract Class<T> getEntityClass();
     
        @Override
        public T create(T entry) {
     
            this.getEntityManager().persist(entry);
     
            return entry;
        }
     
        @Override
        public void createAll(Collection<? extends DAOEntry> entries) {
     
            for (DAOEntry entry : entries) {
                this.getEntityManager().persist(entry);
            }
     
        }
     
        @Override
        public T find(Object id) {
            return this.getEntityManager().find(this.getEntityClass(), id);
        }
     
        @Override
        public Collection<T> findAll() {
            CriteriaQuery<T> cq = this.getEntityManager().getCriteriaBuilder().createQuery(this.getEntityClass());
            cq.select(cq.from(this.getEntityClass()));
            return this.getEntityManager().createQuery(cq).getResultList();
        }
     
        @Override
        public T update(T entry) {
     
            this.getEntityManager().merge(entry);
     
            return entry;
        }
     
        @Override
        public void delete(T entry) {
     
            this.getEntityManager().remove(entry);
     
        }
     
        /**
         * Retrieves the object/entity/model using the key/value pair.
         * 
         * @param fieldName - The name of the key/field.
         * @param value - The value for the specified key/field.
         * @return The entity/object or <code>null</code> if not found.
         */
        @SuppressWarnings("unchecked")
        public T findEntityHavingValue(final String fieldName, final Object value) {
            final String jpql = "SELECT x FROM " + this.getEntityClass().getName() + " x WHERE x." + fieldName + " = :"
                    + fieldName;
            Query q = this.getEntityManager().createQuery(jpql, this.getEntityClass());
            q.setParameter(fieldName, value);
            T result = null;
            try {
                result = (T) q.getSingleResult();
            } catch (NoResultException nre) {
                // No result found !
            }
            return result;
        }
     
        /**
         * Retrieves the list of all entities/objects having the specified value for
         * the specified field.
         * 
         * @param fieldName - The name of the field.
         * @param value - The value for the specified field.
         * @return The list of objects found or an empty list.
         */
        public Collection<T> findAllEntitiesHavingValue(final String fieldName, final Object value) {
            final String jpql = "SELECT x FROM " + this.getEntityClass().getName() + " x WHERE x." + fieldName + " = :"
                    + fieldName;
            Query q = this.getEntityManager().createQuery(jpql, this.getEntityClass());
            q.setParameter(fieldName, value);
            @SuppressWarnings("unchecked")
            List<T> result = q.getResultList();
            return result;
        }
     
        /**
         * Retrieves the specified entity/object using the specified
         * {@link NamedQuery} having the specified name.
         * 
         * @param queryName - The name of the {@link NamedQuery} to use.
         * @param parameters - The list of parameters to passe to the
         *            {@link NamedQuery}.
         * @return The entity/object or <tt>null</tt> if not found.
         */
        @SuppressWarnings("unchecked")
        public T findEntityByUsingQuery(final String queryName, final Map<String, Object> parameters) {
            Query q = this.getEntityManager().createNamedQuery(queryName);
            if (parameters != null) {
                Iterator<Entry<String, Object>> iter = parameters.entrySet().iterator();
                while (iter.hasNext()) {
                    Entry<String, Object> o = iter.next();
                    q.setParameter(o.getKey(), o.getValue());
                }
            }
            T result = null;
            try {
                result = (T) q.getSingleResult();
            } catch (NoResultException nre) {
                // Pas de résultat trouvé !
            }
            return result;
        }
     
        /**
         * Retrieves the list of entities/object using the specified
         * {@link NamedQuery} having the specified name.
         * 
         * @param queryName - The name of the {@link NamedQuery} to use.
         * @param parameters - The list of parameters to pass to the
         *            {@link NamedQuery}.
         * @return The list of entities/objects or an empty list.
         */
        public Collection<T> findAllEntitiesByUsingQuery(String queryName, Map<String, Object> parameters) {
            Query q = this.getEntityManager().createNamedQuery(queryName);
            if (parameters != null) {
                Iterator<Entry<String, Object>> iter = parameters.entrySet().iterator();
                while (iter.hasNext()) {
                    Entry<String, Object> o = iter.next();
                    q.setParameter(o.getKey(), o.getValue());
                }
            }
            @SuppressWarnings("unchecked")
            List<T> result = q.getResultList();
            return result;
        }
     
        /**
         * Permits to close the {@link EntityManager} which is use internally by the
         * {@link DAO}.
         */
        public void closeEntityManager() {
            this.getEntityManager().close();
        }
     
         public int count() {
            CriteriaQuery cq = this.getEntityManager().getCriteriaBuilder().createQuery();
            Root<T> rt = cq.from(getEntityClass());
            cq.select(this.getEntityManager().getCriteriaBuilder().count(rt));
            Query q = this.getEntityManager().createQuery(cq);
            return ((Integer) q.getSingleResult()).intValue();
        }
     
    }
    voici mon 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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package ejb.globalschool_ejb;
     
    import java.util.HashMap;
    import java.util.Map;
    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import org.better.dao.PaysDao;
    import org.better.modele.Pays;
     
    /**
     *
     * @author Administrateur
     */
    @Stateless
    @LocalBean
    public class PaysEJB {
     
        public PaysDao paydao = new PaysDao();
        public Pays payscollect= new Pays();
        Map<String, Object> mesparam = new HashMap<String, Object>();
        //ajouter pays
     
        public Pays Ajouter(Pays P) {
     
            //verifier si le pays existe deja
           payscollect=paydao.find(P.getCode());
           if(payscollect.getCode()==null){
               System.out.print("le pays: "+payscollect.getCode()+" existe deja");
           }else{
               payscollect=paydao.create(P);
               System.out.print("le pays: "+payscollect.getCode()+" avec success");
           }
        return payscollect;
        }
     
    }
    voici mon fichier de test 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
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package ejb.globalschool_ejb;
     
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    import javax.ejb.embeddable.EJBContainer;
    import javax.naming.Context;
    import org.better.modele.Pays;
    import org.junit.*;
     
    /**
     *
     * @author Administrateur
     */
    public class PaysEJBTest {
     
        public static EJBContainer container;
        public static Context appContext;
        public Pays p = new Pays();
     
        @BeforeClass
        //public static void setUpClass() throws Exception {
        public static void initContainer() throws Exception {
            Map<String, Object> props = new HashMap<String, Object>();
            //props.put(EJBContainer.APP_NAME, "matestejb");
            props.put(EJBContainer.MODULES, new File[]{new File("target/classes")});
            props.put("org.glassfish.ejb.embedded.glassfish.installation.root", "C:/Program Files/glassfish-3.1.1/glassfish");
     
            //props.put(EJBContainer.PROVIDER, "org.glassfish.ejb.embedded.EJBContainerProviderImpl");
            //props.put("org.glassfish.ejb.embedded.glassfish.configuration.file", "C:/Program Files/glassfish-3.1.1/glassfish/domains/domain1/config/domain.xml");
            container = EJBContainer.createEJBContainer(props);
            appContext = container.getContext();
        }
     
        @AfterClass
        //public static void tearDownClass() throws Exception {
        public static void closeContainer() throws Exception {
            appContext.close();
            container.close();
        }
     
        @Before
        public void setUp() {
        }
     
        @After
        public void tearDown() {
        }
     
        /**
         * Test of Ajouter method, of class PaysEJB.
         */
        @Test
        public void testAjouter() throws Exception {
            System.out.println("Ajouter");
            p.setCode("CM");
            p.setContinent("AFRIQUE");
            p.setLibelle("Cameroun");
            p.setLibelleAnglais("Cameroon");
     
     
            PaysEJB paystest = (PaysEJB) appContext.lookup("java:global/classes/PaysEJB");
     
            p = paystest.Ajouter(p);
     
     
        }
     
    }
    le fichier de persistence pour les test.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
      <persistence-unit name="GlobalschoolPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>globalschool_jndi</jta-data-source>
     
        <class>org.better.modele.Pays</class>
     
        <properties>
          <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
      </persistence-unit>
    </persistence>
    voici l'erreur
    Infos: classes was successfully deployed in 7*529 milliseconds.
    PlainTextActionReporterSUCCESSDescription: deploy AdminCommandApplication deployed with name classes.
    [name=classes
    junit.framework.TestListener: startTest(testAjouter)
    Ajouter
    mars 27, 2012 10:26:57 AM com.sun.ejb.containers.BaseContainer postInvoke
    Avertissement: A system exception occurred during an invocation on EJB PaysEJB method public org.better.modele.Pays com.better.parametrage.PaysEJB.Ajouter(org.better.modele.Pays)
    javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy91.Ajouter(Unknown Source)
    at com.better.parametrage.__EJB31_Generated__PaysEJB__Intf____Bean__.Ajouter(Unknown Source)
    at com.better.parametrage.PaysEJBTest.testAjouter(PaysEJBTest.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    junit.framework.TestListener: addError(testAjouter, null)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    junit.framework.TestListener: endTest(testAjouter)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
    Caused by: java.lang.NullPointerException
    PlainTextActionReporterSUCCESSNo monitoring data to report.
    at org.better.dao.AbstractJpaDAO.create(AbstractJpaDAO.java:44)
    at com.better.parametrage.PaysEJB.Ajouter(PaysEJB.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    ... 29 more

    mars 27, 2012 10:27:01 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
    Infos: JMXStartupService and JMXConnectors have been shut down.
    mars 27, 2012 10:27:01 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
    Infos: JMXStartupService and JMXConnectors have been shut down.
    mars 27, 2012 10:27:01 AM com.sun.enterprise.v3.server.AppServerStartup stop
    Infos: Shutdown procedure finished
    mars 27, 2012 10:27:01 AM AppServerStartup run
    Infos: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
    Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 21,08 sec

    ------------- Standard Output ---------------
    PlainTextActionReporterSUCCESSDescription: deploy AdminCommandApplication deployed with name classes.
    [name=classes
    Ajouter
    PlainTextActionReporterSUCCESSNo monitoring data to report.
    ------------- ---------------- ---------------
    ------------- Standard Error -----------------
    mars 27, 2012 10:26:46 AM com.sun.enterprise.v3.server.AppServerStartup run
    Infos: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (2*687ms), startup services(1*561ms), total(4*248ms)
    mars 27, 2012 10:26:47 AM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
    Infos: JMXStartupService: JMXConnector system is disabled, skipping.
    mars 27, 2012 10:26:49 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
    Infos: JMXStartupService and JMXConnectors have been shut down.
    mars 27, 2012 10:26:49 AM com.sun.enterprise.v3.server.AppServerStartup stop
    Infos: Shutdown procedure finished
    mars 27, 2012 10:26:49 AM AppServerStartup run
    Infos: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
    mars 27, 2012 10:26:49 AM com.sun.enterprise.v3.server.AppServerStartup run
    Infos: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (6*633ms), startup services(84ms), total(6*717ms)
    mars 27, 2012 10:26:49 AM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
    Infos: JMXStartupService: JMXConnector system is disabled, skipping.
    mars 27, 2012 10:26:49 AM org.glassfish.ejb.embedded.EJBContainerImpl deploy
    Infos: [EJBContainerImpl] Deploying app: target\classes
    mars 27, 2012 10:26:51 AM org.hibernate.validator.util.Version <clinit>
    Infos: Hibernate Validator 4.1.0.Final
    mars 27, 2012 10:26:51 AM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
    Infos: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    mars 27, 2012 10:26:53 AM com.sun.enterprise.security.SecurityLifecycle <init>
    Infos: SEC1002: Security Manager is OFF.
    mars 27, 2012 10:26:53 AM com.sun.enterprise.security.SecurityLifecycle onInitialization
    Infos: SEC1010: Entering Security Startup Service
    mars 27, 2012 10:26:53 AM com.sun.enterprise.security.PolicyLoader loadPolicy
    Infos: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
    mars 27, 2012 10:26:54 AM com.sun.enterprise.security.auth.realm.Realm doInstantiate
    Infos: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
    mars 27, 2012 10:26:54 AM com.sun.enterprise.security.auth.realm.Realm doInstantiate
    Infos: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
    mars 27, 2012 10:26:54 AM com.sun.enterprise.security.auth.realm.Realm doInstantiate
    Infos: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
    mars 27, 2012 10:26:54 AM com.sun.enterprise.security.SecurityLifecycle onInitialization
    Infos: SEC1011: Security Service(s) Started Successfully
    mars 27, 2012 10:26:56 AM com.sun.ejb.containers.BaseContainer initializeHome
    Infos: Portable JNDI names for EJB PaysEJB : [java:global/classes/PaysEJB, java:global/classes/PaysEJB!com.better.parametrage.PaysEJB]
    mars 27, 2012 10:26:57 AM org.glassfish.deployment.admin.DeployCommand execute
    Infos: classes was successfully deployed in 7*529 milliseconds.
    mars 27, 2012 10:26:57 AM com.sun.ejb.containers.BaseContainer postInvoke
    Avertissement: A system exception occurred during an invocation on EJB PaysEJB method public org.better.modele.Pays com.better.parametrage.PaysEJB.Ajouter(org.better.modele.Pays)
    javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy91.Ajouter(Unknown Source)
    at com.better.parametrage.__EJB31_Generated__PaysEJB__Intf____Bean__.Ajouter(Unknown Source)
    at com.better.parametrage.PaysEJBTest.testAjouter(PaysEJBTest.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
    Caused by: java.lang.NullPointerException
    at org.better.dao.AbstractJpaDAO.create(AbstractJpaDAO.java:44)
    at com.better.parametrage.PaysEJB.Ajouter(PaysEJB.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5
    Test com.better.parametrage.PaysEJBTest FAILED
    -check-run-test-single-method-supported:
    Skipped because property 'methodname' not set.
    -test-method:
    Skipped because property 'methodname' not set.
    test:
    Deleting: C:\Users\fabrice\AppData\Local\Temp\TEST-com.better.parametrage.PaysEJBTest.xml
    GÉNÉRATION TERMINÉE (durée totale* 32 secondes)
    Précision en modifiant mon EJB avec manipulation directe de mon entity manager ça marche

    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
    package ejb.globalschool_ejb;
     
    import java.util.HashMap;
    import java.util.Map;
    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import org.better.dao.PaysDao;
    import org.better.modele.Pays;
     
    /**
     *
     * @author Administrateur
     */
    @Stateless
    @LocalBean
    public class PaysEJB {
     
      @PersistenceContext(name="Globalschool_PU")
        private EntityManager em;
     
        public Pays payscollect= new Pays();
        Map<String, Object> mesparam = new HashMap<String, Object>();
        //ajouter pays
     
        public Pays Ajouter(Pays P) {
     
     
               payscollect=em.persist(P);
               System.out.print("le pays: "+payscollect.getCode()+" avec success");
     
        return payscollect;
        }
     
    }
    Ce qui ne me tue pas me rend plus fort.

  2. #2
    Membre confirmé
    Avatar de Khaled.Noordin
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    354
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 354
    Points : 497
    Points
    497
    Billets dans le blog
    1
    Par défaut
    globalschool_jndi n'est pas un nom standard de source de données, regarde de plus près des exemples tu verra que cela doit ressembler a un appel de nom du style "jdbc/maDataSource"

  3. #3
    Membre confirmé Avatar de bruneltouopi
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2010
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

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

    Informations forums :
    Inscription : Janvier 2010
    Messages : 308
    Points : 466
    Points
    466
    Par défaut
    le problème ne provient pas du nom de la source de données mais tu as raison jdbc/datasource.donc là n'est pas le souci car comme je l'ai dit.j'ai mis jdbc/Globalschool_jndi.
    J'ai un peu cherché et je constate que étant donné que ma couche DAO est dans un module de type application.je ne peux pas utiliser @persistencecontext dans l'abstractDAO ou dans ce module.
    Il faut que soit j'utilise le CDI soit je le mets directement dans un projet EJB.

    J'ai opté pour la deuxième solution et j'ai décoré mes classes DAO avec @Stateless bref j'ai un peu adapté cela au pattern DAO par défaut de jee6.mais j'ai toujours ce nullpointer exception au niveau de ma méthode create de l'abstract DAO.
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package org.better.dao;
     
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import org.better.modele.Pays;
    import javax.ejb.Stateless;
    /**
     *
     * @author JEANNE
     */
    @Stateless
    public class PaysDao extends AbstractJpaDAO<Pays> {
        private static final long serialVersionUID = 1L;
        @PersistenceContext(unitName=AbstractJpaDAO.PersistanceUnit)
        private EntityManager em;
     
     
     
        @Override
        protected EntityManager getEntityManager() {
            return em;
        }
        @Override
        protected Class<Pays> getEntityClass() {
            return Pays.class;
        }
     
    }
    et mon Abstract

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
     
    package org.better.dao;
     
     
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    import javax.persistence.*;
    import javax.persistence.criteria.CriteriaQuery;
    import javax.persistence.criteria.Root;
    import org.better.modele.DAOEntry;
     
    // CLASSE ABSTRAITE PERMETTANT DE MANIPULER L INTERFACE DAO
     
    public abstract class AbstractJpaDAO<T extends DAOEntry> implements DAO<T> {
     
        private static final long serialVersionUID = 1L;
        public static final String PersistanceUnit="GlobalschoolPU";
        /**
         * @return The type of the class of the entity to work with.
         */
        protected abstract Class<T> getEntityClass();
     
     
        protected abstract EntityManager getEntityManager();
     
     
    //    protected EntityManager getEntityManager() {
    //        return em;
    //    }
     
     
        protected AbstractJpaDAO() {
        }
     
     
     
        @Override
        public void create(T entry) {
     
            this.getEntityManager().persist(entry);
     
        }
     
        @Override
        public void createAll(Collection<? extends DAOEntry> entries) {
     
            for (DAOEntry entry : entries) {
                this.getEntityManager().persist(entry);
            }
     
        }
     
        @Override
        public T find(Object id) {
            return this.getEntityManager().find(this.getEntityClass(), id);
        }
     
        @Override
        public Collection<T> findAll() {
            CriteriaQuery<T> cq = this.getEntityManager().getCriteriaBuilder().createQuery(this.getEntityClass());
            cq.select(cq.from(this.getEntityClass()));
            return this.getEntityManager().createQuery(cq).getResultList();
        }
     
        @Override
        public void update(T entry) {
     
            this.getEntityManager().merge(entry);
     
        }
     
        @Override
        public void delete(T entry) {
     
            this.getEntityManager().remove(entry);
     
        }
     
        /**
         * Retrieves the object/entity/model using the key/value pair.
         * 
         * @param fieldName - The name of the key/field.
         * @param value - The value for the specified key/field.
         * @return The entity/object or <code>null</code> if not found.
         */
        @SuppressWarnings("unchecked")
        public T findEntityHavingValue(final String fieldName, final Object value) {
            final String jpql = "SELECT x FROM " + this.getEntityClass().getName() + " x WHERE x." + fieldName + " = :"
                    + fieldName;
            Query q = this.getEntityManager().createQuery(jpql, this.getEntityClass());
            q.setParameter(fieldName, value);
            T result = null;
            try {
                result = (T) q.getSingleResult();
            } catch (NoResultException nre) {
                // No result found !
            }
            return result;
        }
     
        /**
         * Retrieves the list of all entities/objects having the specified value for
         * the specified field.
         * 
         * @param fieldName - The name of the field.
         * @param value - The value for the specified field.
         * @return The list of objects found or an empty list.
         */
        public Collection<T> findAllEntitiesHavingValue(final String fieldName, final Object value) {
            final String jpql = "SELECT x FROM " + this.getEntityClass().getName() + " x WHERE x." + fieldName + " = :"
                    + fieldName;
            Query q = this.getEntityManager().createQuery(jpql, this.getEntityClass());
            q.setParameter(fieldName, value);
            @SuppressWarnings("unchecked")
            List<T> result = q.getResultList();
            return result;
        }
     
        /**
         * Retrieves the specified entity/object using the specified
         * {@link NamedQuery} having the specified name.
         * 
         * @param queryName - The name of the {@link NamedQuery} to use.
         * @param parameters - The list of parameters to passe to the
         *            {@link NamedQuery}.
         * @return The entity/object or <tt>null</tt> if not found.
         */
        @SuppressWarnings("unchecked")
        public T findEntityByUsingQuery(final String queryName, final Map<String, Object> parameters) {
            Query q = this.getEntityManager().createNamedQuery(queryName);
            if (parameters != null) {
                Iterator<Entry<String, Object>> iter = parameters.entrySet().iterator();
                while (iter.hasNext()) {
                    Entry<String, Object> o = iter.next();
                    q.setParameter(o.getKey(), o.getValue());
                }
            }
            T result = null;
            try {
                result = (T) q.getSingleResult();
            } catch (NoResultException nre) {
                // Pas de résultat trouvé !
            }
            return result;
        }
     
        /**
         * Retrieves the list of entities/object using the specified
         * {@link NamedQuery} having the specified name.
         * 
         * @param queryName - The name of the {@link NamedQuery} to use.
         * @param parameters - The list of parameters to pass to the
         *            {@link NamedQuery}.
         * @return The list of entities/objects or an empty list.
         */
        public Collection<T> findAllEntitiesByUsingQuery(String queryName, Map<String, Object> parameters) {
            Query q = this.getEntityManager().createNamedQuery(queryName);
            if (parameters != null) {
                Iterator<Entry<String, Object>> iter = parameters.entrySet().iterator();
                while (iter.hasNext()) {
                    Entry<String, Object> o = iter.next();
                    q.setParameter(o.getKey(), o.getValue());
                }
            }
            @SuppressWarnings("unchecked")
            List<T> result = q.getResultList();
            return result;
        }
     
        /**
         * Permits to close the {@link EntityManager} which is use internally by the
         * {@link DAO}.
         */
        public void closeEntityManager() {
            this.getEntityManager().close();
        }
     
         public int count() {
            CriteriaQuery cq = this.getEntityManager().getCriteriaBuilder().createQuery();
            Root<T> rt = cq.from(getEntityClass());
            cq.select(this.getEntityManager().getCriteriaBuilder().count(rt));
            Query q = this.getEntityManager().createQuery(cq);
            return ((Integer) q.getSingleResult()).intValue();
        }
     
    }
    Ce qui ne me tue pas me rend plus fort.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    365
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Janvier 2006
    Messages : 365
    Points : 495
    Points
    495
    Par défaut
    Bonjour,

    Tu as des NullPointerException à partir du moment où dans l'ejb PaysEJB tu instancies directement le dao:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public PaysDao paydao = new PaysDao();
    Cette instantiation n'étant pas faite par le container, l'EntityManager n'est donc pas injecté et reste nulll.

    Effectivement, si tu veux que tes DAOs restent de simples POJOs comme dans ta première solution, il te faudrait utiliser CDI pour faire l'injection de l'EntityManager dans le DAO PaysDao et ensuite l'injection du DAO dans l'ejb PaysEJB.
    Tout est fait de manière transparente, et si tu es déjà dans un environnement Java EE 6, il te suffirait d'ajouter le fichier beans.xml pour activer CDI.

    Mais si, comme j'ai compris, tu ne peux pas utiliser CDI, alors ta dernière solution qui consiste à transformer tes DAO en EJB en les annotant @Stateless est la meilleure voie à suivre.
    Dans ce cas, il te reste simplement à injecter l'ejb PaysDao dans l'ejb façade PaysEJB, au lieu d'une instantiation avec new, et tout est bon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    @EJB private PaysDao paysDao;

    Si tout si tout le reste est OK, ceci devrait marcher.
    SCJP 5 / SCBCD 1.3 Certified

  5. #5
    Membre confirmé Avatar de bruneltouopi
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2010
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

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

    Informations forums :
    Inscription : Janvier 2010
    Messages : 308
    Points : 466
    Points
    466
    Par défaut
    oui effectivement j'ai opté pour la deuxième solution et c'est OK j'arrive à tester ces EJB dans le projet.

    Mais j'ai un autre souci car en fait etant donné qui j'ai envie de créer plusieurs modules Maven de type EJB et je veux appeller appeller ces services DAO dans les autres projets

    j'ai un souci avec le test il n'arrive pas à reconnaitre le l'injection de l'ejb DAO.

    Voici mon fichier paysDAO se trouvant dans le module globalschool_daojpa
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package org.better.dao;
     
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import org.better.modele.Pays;
    import javax.ejb.Stateless;
    /**
     *
     * @author JEANNE
     */
    @Stateless
    public class PaysDao extends AbstractJpaDAO<Pays> {
        private static final long serialVersionUID = 1L;
        @PersistenceContext(unitName=AbstractJpaDAO.PersistanceUnit)
        private EntityManager em;
     
     
     
        @Override
        protected EntityManager getEntityManager() {
            return em;
        }
        @Override
        protected Class<Pays> getEntityClass() {
            return Pays.class;
        }
     
    }
    voici le code PaysEJB se trouvant dans le module Globalschool_parametrage
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.better.parametrage;
     
    import java.util.HashMap;
    import java.util.Map;
    import javax.ejb.EJB;
    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import org.better.dao.PaysDao;
    import org.better.modele.Pays;
     
    /**
     *
     * @author Administrateur
     */
    @Stateless
    @LocalBean
    public class PaysEJB {
        @EJB
        private PaysDao paydao;
     
        Map<String, Object> mesparam = new HashMap<String, Object>();
        //ajouter pays
     
        public void Ajouter(Pays P) {
     
            paydao.create(P);
               System.out.print("le pays: "+P.getCode()+" avec success");
    //       }
        }
     
    }
    fichier de test se trouvant dans le même projet
    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
    72
    73
    74
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.better.parametrage;
     
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    import javax.ejb.EJB;
    import javax.ejb.embeddable.EJBContainer;
    import javax.naming.Context;
    import org.better.modele.Pays;
    import org.junit.*;
     
    /**
     *
     * @author Administrateur
     */
    public class PaysEJBTest {
     
        public static EJBContainer container;
        public static Context appContext;
        public Pays p = new Pays();
     
     
        @BeforeClass
        //public static void setUpClass() throws Exception {
        public static void initContainer() throws Exception {
            Map<String, Object> props = new HashMap<String, Object>();
            //props.put(EJBContainer.APP_NAME, "matestejb");
            props.put(EJBContainer.MODULES, new File[]{new File("target/classes")});
            props.put("org.glassfish.ejb.embedded.glassfish.installation.root", "C:/Program Files/glassfish-3.1.1/glassfish");
     
            //props.put(EJBContainer.PROVIDER, "org.glassfish.ejb.embedded.EJBContainerProviderImpl");
            //props.put("org.glassfish.ejb.embedded.glassfish.configuration.file", "C:/Program Files/glassfish-3.1.1/glassfish/domains/domain1/config/domain.xml");
            container = EJBContainer.createEJBContainer(props);
            appContext = container.getContext();
        }
     
        @AfterClass
        //public static void tearDownClass() throws Exception {
        public static void closeContainer() throws Exception {
            appContext.close();
            container.close();
        }
     
        @Before
        public void setUp() {
        }
     
        @After
        public void tearDown() {
        }
     
        /**
         * Test of Ajouter method, of class PaysEJB.
         */
        @Test
        public void testAjouter() throws Exception {
            System.out.println("Ajouter");
            p.setCode("US");
            p.setContinent("AMERIQUE");
            p.setLibelle("usa");
            p.setLibelleAnglais("usa");
     
     
           PaysEJB paystest = (PaysEJB) appContext.lookup("java:global/classes/PaysEJB");
     
            paystest.Ajouter(p);
     
        }
     
    }
    voici l'erreur du au lookup je crois @EJB paysdao présent dans PaysEJB
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    Avertissement: A system exception occurred during an invocation on EJB PaysEJB method public void com.better.parametrage.PaysEJB.Ajouter(org.better.modele.Pays)
    javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
    	at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2528)
    	at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1895)
    	at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    	at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    	at $Proxy92.Ajouter(Unknown Source)
    	at com.better.parametrage.__EJB31_Generated__PaysEJB__Intf____Bean__.Ajouter(Unknown Source)
    	at com.better.parametrage.PaysEJBTest.testAjouter(PaysEJBTest.java:70)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    	at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
    	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
    Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:726)
    	at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:247)
    	at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:449)
    	... 32 more
    Caused by: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:534)
    	at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:95)
    	at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:724)
    	... 34 more
    Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session into class com.better.parametrage.PaysEJB: Lookup failed for 'java:comp/env/com.better.parametrage.PaysEJB/paydao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
    	at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1691)
    	at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:494)
    	... 36 more
    Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/com.better.parametrage.PaysEJB/paydao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'org.better.dao.PaysDao#org.better.dao.PaysDao' [Root exception is javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]]]
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    	at javax.naming.InitialContext.lookup(InitialContext.java:411)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
    	... 40 more
    Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'org.better.dao.PaysDao#org.better.dao.PaysDao' [Root exception is javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]]
    	at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:178)
    	at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1106)
    	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
    	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
    	at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:172)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
    	... 43 more
    Caused by: javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    	at javax.naming.InitialContext.lookup(InitialContext.java:411)
    	at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:173)
    	... 48 more
    Caused by: javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found
    	at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
    	at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
    	at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    	at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
    	... 51 more
     
    mars 28, 2012 2:35:58 PM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
    Infos: JMXStartupService and JMXConnectors have been shut down.
    mars 28, 2012 2:35:58 PM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
    Infos: JMXStartupService and JMXConnectors have been shut down.
    mars 28, 2012 2:35:58 PM com.sun.enterprise.v3.server.AppServerStartup stop
    Infos: Shutdown procedure finished
    mars 28, 2012 2:35:58 PM AppServerStartup run
    Infos: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
    ------------- ---------------- ---------------
    Testcase: testAjouter(com.better.parametrage.PaysEJBTest):	Caused an ERROR
    javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
    	at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2528)
    	at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1895)
    	at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    	at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    	at $Proxy92.Ajouter(Unknown Source)
    	at com.better.parametrage.__EJB31_Generated__PaysEJB__Intf____Bean__.Ajouter(Unknown Source)
    	at com.better.parametrage.PaysEJBTest.testAjouter(PaysEJBTest.java:70)
    Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:726)
    	at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:247)
    	at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:449)
    Caused by: javax.ejb.CreateException: Could not create stateless EJB
    	at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:534)
    	at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:95)
    	at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:724)
    Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session into class com.better.parametrage.PaysEJB: Lookup failed for 'java:comp/env/com.better.parametrage.PaysEJB/paydao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
    	at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1691)
    	at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:494)
    Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/com.better.parametrage.PaysEJB/paydao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'org.better.dao.PaysDao#org.better.dao.PaysDao' [Root exception is javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]]]
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    	at javax.naming.InitialContext.lookup(InitialContext.java:411)
    	at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
    Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.better.parametrage.PaysEJB/paydao,Remote 3.x interface =org.better.dao.PaysDao,ejb-link=null,lookup=,mappedName=,jndi-name=org.better.dao.PaysDao,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'org.better.dao.PaysDao#org.better.dao.PaysDao' [Root exception is javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]]
    	at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:178)
    	at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1106)
    	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
    	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
    	at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:172)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
    Caused by: javax.naming.NamingException: Lookup failed for 'org.better.dao.PaysDao#org.better.dao.PaysDao' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found]
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    	at javax.naming.InitialContext.lookup(InitialContext.java:411)
    	at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:173)
    Caused by: javax.naming.NameNotFoundException: org.better.dao.PaysDao#org.better.dao.PaysDao not found
    	at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
    	at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
    	at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    	at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
    Ce qui ne me tue pas me rend plus fort.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    365
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Janvier 2006
    Messages : 365
    Points : 495
    Points
    495
    Par défaut
    Hmmm... je vois.

    Il faut remarquer qu'ici le dao PaysDao est défini comme un ejb sans interface locale ou remote, et donc utilise une no-interface view, ou @LocalBean, introduite dans EJB 3.1.

    Pour que l'injection ou lookup d'un ejb à partir de sa no-interface view puisse fonctionner, l'ejb et son client doivent être déployés dans le même module ejb ou la même application (EAR).

    C'est d'ailleurs pour ça que le lookup de PaysEJB dans PaysEJBTest fonctionne, puisqu'ils sont dans le même module Globalschool_parametrage.

    Et donc, pour résoudre ton problème, il faudrait soit que tes ejb DAOs implémentent des interfaces annotées @Local ou @Remote et ensuite faire l'injection en déclarant l'interface et non la classe bean, soit packager tous ces modules dans un seul EAR (ou WAR puisque visiblement tu es en environnement jee6).

    J'espère que ça va te débloquer.
    SCJP 5 / SCBCD 1.3 Certified

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/01/2015, 16h49
  2. [EJB3 Entity] Création d'un entity Manager pour transaction
    Par bizet dans le forum Java EE
    Réponses: 4
    Dernier message: 23/02/2007, 08h58
  3. Réponses: 3
    Dernier message: 11/06/2006, 19h03

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