Convert transactional EJB to Web Service
gllambi Sep 22, 2009 5:53 PMHi, I'm doing some tests with JBossTS, WS-AT and interoperability with .NET.
This is the first phase towards this tests and I got the following problem. I want to expose a transactional ejb (no WS-AT transactions, simple JTA) as a Web Service. EJB alone works well, unfortunatelly, when I expose it as a Web Service an error occurs with the creation of the transactional session. Is it possible to expose a transactional ejb to a WebService?
Here is the ejb code:
@Stateless @LocalBinding (jndiBinding="PepeBankServices/PepeBankLocal") @WebService public class PepeBankService implements IPepeBankServiceLocal { @PersistenceContext(unitName="PepeBankPersistence") protected EntityManager em; public PepeBankService() { } @WebMethod public Cuenta consultar(@WebParam(name="idCuenta") long idCuenta) throws BankException { Cuenta cuenta = (Cuenta)em.createQuery("select c from Cuenta c where c.id_cuenta = ?1"). setParameter(1, idCuenta).getResultList().get(0); return cuenta; } }
and here is the error stack trace:
2009-09-22 17:47:08,328 INFO [STDOUT] (http-127.0.0.1-8080-3) Create Web Service...<br> 2009-09-22 17:47:08,812 INFO [STDOUT] (http-127.0.0.1-8080-3) Call Web Service Operation...<br> 2009-09-22 17:47:08,999 WARN [org.jboss.ejb3.stateless.StatelessBeanContext] (http-127.0.0.1-8080-1) EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected 2009-09-22 17:47:09,015 WARN [org.jboss.ejb3.stateless.StatelessBeanContext] (http-127.0.0.1-8080-1) EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected 2009-09-22 17:47:09,031 ERROR [org.hibernate.LazyInitializationException] (http-127.0.0.1-8080-1) failed to lazily initialize a collection of role: uy.edu.fing.lins.persistence.Cliente.cuentas, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: uy.edu.fing.lins.persistence.Cliente.cuentas, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108) at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) 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.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.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:151) at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:185) at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:305) at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:312) at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:71) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
Thank you very much!
Guzmán