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;
    }
 
}