4

我正在制作一个具有分布式架构的项目,但在返回java.util.Collection客户端应用程序时遇到问题。

我在托管 Bean 中调用 EJB 以带来持久实体的集合。

我正在使用 Java7 和 JBoss7.1.1。

ManagedBean 方法:

public Collection<Cliente> getClientes() {

   clientes=new ArrayList<Cliente>();

   try {

   Context ctx = new InitialContext();

   facade = (ClienteFacadeRemote) ctx.lookup(ClienteFacadeBean.NOME_EJB);

   } catch (NamingException e) {

     e.printStackTrace();
   }

   clientes = facade.getCarteira();

   return clientes;

}

EJB 方法:

public Collection<Cliente> getCarteira() {
    carteira = clienteDao.read(Cliente.QUERY_ALL);
    return carteira;
}

clienteDao.read(Cliente.QUERY_ALL)方法查找实体并填充集合。然而,回到托管 Bean,我们有堆栈跟踪:

javax.faces.el.EvaluationException: java.lang.RuntimeException: ClassNotFoundException marshaling EJB parameters
    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    javax.faces.component.UICommand.broadcast(UICommand.java:315)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
root cause

java.lang.RuntimeException: ClassNotFoundException marshaling EJB parameters
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:229)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:188)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179)
    org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    $Proxy31.getCarteira(Unknown Source)
    br.tcc.faetec.managedbean.ClienteMB.getTeste(ClienteMB.java:316)
    br.tcc.faetec.managedbean.ClienteMB.teste(ClienteMB.java:410)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.apache.el.parser.AstValue.invoke(AstValue.java:262)
    org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    javax.faces.component.UICommand.broadcast(UICommand.java:315)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
root cause

java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag from [Module "deployment.external./home/marcos/tccmodel.jar:main" from Service Module Loader]
    org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
    org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
    org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Class.java:264)
    org.jboss.marshalling.cloner.ClassLoaderClassCloner.clone(ClassLoaderClassCloner.java:46)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:158)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:187)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
    org.jboss.marshalling.cloner.SerializingCloner.cloneFields(SerializingCloner.java:348)
    org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:309)
    org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:286)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:254)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
    org.jboss.marshalling.cloner.SerializingCloner$StepObjectInput.doReadObject(SerializingCloner.java:738)
    org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)
    org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:57)
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:363)
    java.util.ArrayList.readObject(ArrayList.java:733)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:213)
    org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:302)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:254)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:225)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:188)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179)
    org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    $Proxy31.getCarteira(Unknown Source)
    br.tcc.faetec.managedbean.ClienteMB.getTeste(ClienteMB.java:316)
    br.tcc.faetec.managedbean.ClienteMB.teste(ClienteMB.java:410)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.apache.el.parser.AstValue.invoke(AstValue.java:262)
    org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    javax.faces.component.UICommand.broadcast(UICommand.java:315)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
4

1 回答 1

3

jboss-deployment-structure.xml在您的 WEB-INF 文件夹中放置一个文件:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
        <module name="javaee.api" />
        <module name="org.hibernate" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>
于 2013-04-24T22:13:25.563 回答