As tu besoin de te connecter à tes entités par un client "lourd" java ?
A mon avis tu veux faire que du web, donc enlève l'interface Remote...
Version imprimable
qu'appelle tu client "lourd" et j'ai enlever mais sa marche pas j'ai une probleme avec l'authentificate clientfacadelocal , dans le clientfacade il dit qu'il n'est pas abstract de sa =s je crois que je vais désinstaller netbeans et trouver une autre version pour voir si ya pas l'onglet session bean parceque sa commence a me prendre la tete :/
Normal, j'avais mis une fonction d'authentification pour un client...
Donc si tu gardes cette fonction dans le facadelocal, il faut l'implémenter dans ton bean de session...
Sinon enlève la déclaration du facadelocal !
RAPPEL : une interface, est un contrat ! Donc si ton bean de session implémente une interface, toutes les fonctions déclarées doivent figurer dans ta classe...
Or dans ton cas, on utilise l'héritage d'une AbstractClass qui implémente toutes les fonctions hormis authenticate() !
C'est sûr que ça serait plus facile !!!
je crois que j'ai trouver en fait j'ai un autre onglet qui s'appelle "JPA controller classes from entity classes " et sa regroupe tes 3 pages voila le code :
donc moi au lieue de client sa s'appelle rpt pour rapport et donc du coup par contre pour le bean je ne sais pas trop comment le faire parceque je n'ai pas la fonction findall mais il y a findWrsRptEntities() est ce qu'a ton avis sa reviendrais au memeCode:
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 package beanPackage; import beanPackage.exceptions.NonexistentEntityException; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.Query; import javax.persistence.EntityNotFoundException; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; /** * * @author stag */ public class WrsRptJpaController { public WrsRptJpaController() { emf = Persistence.createEntityManagerFactory("wrs_automationPU"); } private EntityManagerFactory emf = null; public EntityManager getEntityManager() { return emf.createEntityManager(); } public void create(WrsRpt wrsRpt) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); em.persist(wrsRpt); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } } public void edit(WrsRpt wrsRpt) throws NonexistentEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); wrsRpt = em.merge(wrsRpt); em.getTransaction().commit(); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = wrsRpt.getRptId(); if (findWrsRpt(id) == null) { throw new NonexistentEntityException("The wrsRpt with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } } public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); WrsRpt wrsRpt; try { wrsRpt = em.getReference(WrsRpt.class, id); wrsRpt.getRptId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException("The wrsRpt with id " + id + " no longer exists.", enfe); } em.remove(wrsRpt); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } } public List<WrsRpt> findWrsRptEntities() { return findWrsRptEntities(true, -1, -1); } public List<WrsRpt> findWrsRptEntities(int maxResults, int firstResult) { return findWrsRptEntities(false, maxResults, firstResult); } private List<WrsRpt> findWrsRptEntities(boolean all, int maxResults, int firstResult) { EntityManager em = getEntityManager(); try { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(WrsRpt.class)); Query q = em.createQuery(cq); if (!all) { q.setMaxResults(maxResults); q.setFirstResult(firstResult); } return q.getResultList(); } finally { em.close(); } } public WrsRpt findWrsRpt(Integer id) { EntityManager em = getEntityManager(); try { return em.find(WrsRpt.class, id); } finally { em.close(); } } public int getWrsRptCount() { EntityManager em = getEntityManager(); try { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); Root<WrsRpt> rt = cq.from(WrsRpt.class); cq.select(em.getCriteriaBuilder().count(rt)); Query q = em.createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } finally { em.close(); } } }
j'ai mis sa dans mon bean :
mais sa ne marche pas et j'ai "erreur lors de linjection de ressources dans lebean géré rptBean"Code:
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 import javax.ejb.*; import java.util.*; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped /** * * @author stag */ public class RptBean { @EJB private WrsRptJpaController ejb; private List<WrsRpt> clientList; /** Creates a new instance of ClientBean */ public RptBean() { } @PostConstruct private void load() { clientList = ejb.findWrsRptEntities(); } public List<WrsRpt> getClientList() { return clientList; } }
aurai tu une solution ou quelqu'un d'autre aussi s'il vous palit ?
j'ai généré ce code à partir de la session beans categorie persistence pour les étapes de la connexion à la base mais j'ai trouvé une erreur comme la montre la figure ci-dessous:
Pièce jointe 98898
quelqu'un peut m'aider svp :cry:Code:
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 package bean; import java.util.List; import javax.persistence.EntityManager; /** * * @author chaima.jemmali.stg */ public abstract class AbstractFacade<T> { private Class<T> entityClass; public AbstractFacade(Class<T> entityClass) { this.entityClass = entityClass; } protected abstract EntityManager getEntityManager(); public void create(T entity) { getEntityManager().persist(entity); } public void edit(T entity) { getEntityManager().merge(entity); } public void remove(T entity) { getEntityManager().remove(getEntityManager().merge(entity)); } public T find(Object id) { return getEntityManager().find(entityClass, id); } public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); } public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); } public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root<T> rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } }
et merci d'avance :)