Bonjour, je travail sur projet utilisant des ejb3 + hibernate+ jpa +webservice.
je developpe sous netbeans et j utilise glassfish comme serveur d application.
J ai deux entiy bean,
un entity user avec les attributs suivants
et un autre group
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 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id_spy_user") private Integer idSpyUser; @Basic(optional = false) @Column(name = "email") private String email; @Basic(optional = false) @Column(name = "password") private String password; @Column(name = "first_name") private String firstName; @Column(name = "last_name") private String lastName; @Column(name = "phone") private String phone; @Lob @Column(name = "address") private String address; @Column(name = "session") private String session; @JoinColumn(name = "spy_user_group", referencedColumnName = "id_spy_user_group") @ManyToOne private SpyUserGroup spyUserGroup;
j utilise un session bean qui fait appel a un persistence manager, dont voici le code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id_spy_user_group") private Integer idSpyUserGroup; @Basic(optional = false) @Column(name = "name") private String name; @OneToMany(mappedBy = "spyUserGroup") private List<SpyUser> spyUserCollection;
ce seesion bean est appele tout d abord par un autre session bean, qui verifie si un user et admin ou pas avant de faire appel a la methode findAll
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 @PersistenceContext private EntityManager em; @Override public List<SpyUser> findAll() { return em.createQuery("select object(o) from SpyUser as o").getResultList(); }
voici le code
@EJB
private UserSessionLocal userSessionBean;
@EJB
private SpyUserFacadeLocal userFacade;
public List<SpyUser> getUsers(String key) {
List<SpyUserProtected> spyUserList = new ArrayList();
try {
if (userSessionBean.setSession(key) && getUserByKey(key).getSpyUserGroup().getName().equals("admin")) {
List<SpyUser> spyUserSrc = userFacade.findAll();
return spyUserSrc;
}
} catch (Exception ex) {
Logger.getLogger(UserControllerBean.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
la methode getUsers et expose par un webservice
L exception arrive quand je fais appel a la methode du web service par la page web que l on obtien avec netbeans en faisant test webservice.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 @EJB private UserControllerLocal ejbUserRef; // Add business logic below. (Right-click in editor and choose // "Web Service > Add Operation" @WebMethod(operationName = "getUsers") public List<SpyUser> getUsers(@WebParam(name = "key") String key) { return ejbUserRef.getUsers(key); }
auparavant la base a etait rempli par une classe config qui est appele par un programme de test junit.
donc l erreur et la suivante
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 Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: entity.UserGroup.userCollection, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) at com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.iterator(Lister.java:278) at com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.iterator(Lister.java:265) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:129) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681) at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681) at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:277) at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:100) at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:141) at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:315) at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142) at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108) at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:258) at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320) at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93) at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454) at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135) at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:176)
j ai fais quelques recherches sur le forum mais j ai rien trouve de bien concluant,
merci de prendre un peu de temps pour me repondre.
Partager