"EJB3Trail/StatelessCalculator/local"
Calculator cal = (Calculator) ctx.lookup(Calculator.class.getName());
javax.naming.NameNotFoundException: com.lyh.ejb.Calculator not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:19)
Calculator cal = (Calculator) ctx.lookup("EJB3Trail/StatelessCalculator");
javax.naming.NameNotFoundException: StatelessCalculator not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
at org.jnp.server.NamingServer.lookup(NamingServer.java:255)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:19)
Calculator cal = (Calculator) ctx.lookup("EJB3Trail");
Exception in thread "main" java.lang.ClassCastException: org.jnp.interfaces.NamingContext
at com.lyh.ejb.SampleClient.main(SampleClient.java:19)
package com.lyh.ejb;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SampleClient {
public SampleClient() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
InitialContext ctx;
try {
ctx = new InitialContext();
Calculator cal = (Calculator) ctx.lookup("EJB3Trail/LocalCalculator");
double x = cal.calculate(100, 200, 20, 2000.0);
System.out.println(x);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
原 EJB3Trail/LocalCalculator/local
EJB3Trail/LocalCalculator/
javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.ejb3.stateless.StatelessRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 2583299153931800023, local class serialVersionUID = -9097306519795868]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:723)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:20)
Caused by: java.io.InvalidClassException: org.jboss.ejb3.stateless.StatelessRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 2583299153931800023, local class serialVersionUID = -9097306519795868
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:653)
... 3 more
导入jboss-EJB-3.0_Embeddable_ALPHA_7/lib/*.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/aspects/asynch/AsynchProvider
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredField(Unknown Source)
at java.io.ObjectStreamClass.getDeclaredSUID(Unknown Source)
at java.io.ObjectStreamClass.access$600(Unknown Source)
at java.io.ObjectStreamClass$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.
at java.io.ObjectStreamClass.lookup(Unknown Source)
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:57)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:637)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:20)
导入server/all/deploy/ejb3.deployer/jboss-ejb3.jar
javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no security manager: RMI class loader disabled)]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:20)
Caused by: java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:57)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:637)
... 3 more
把jboss下的jnp包引用一下
位置在jboss-home/client/jnp-client.jar
Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
缺少jboss-client.jar文件
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger
at org.jnp.interfaces.NamingContext.
at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:41)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.
at com.lyh.ejb.SampleClient.main(SampleClient.java:19)
Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
解決方式:
在classpath內,加上%JBoss Home%/client/jbossall-client.jar
我用google找了很久,發現大多初次接觸開發EJB的人,都有遇到這個錯誤訊息,終於在今天我找到了真正可以解決的方法.希望能幫得上忙.
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.
at com.lyh.ejb.SampleClient.main(SampleClient.java:19)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 5 more
try {
ctx = new InitialContext();
Calculator cal = (Calculator) ctx.lookup("EJB3Trail/RemoteCalculator");
double x=cal.calculate(100,200,20,2000.0);
System.out.println(x);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: Exception creating connection to: 192.168.100.88; nested exception is:
java.net.NoRouteToHostException: No route to host: connect]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:723)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb.SampleClient.main(SampleClient.java:20)
Caused by: java.rmi.ConnectIOException: Exception creating connection to: 192.168.100.88; nested exception is:
java.net.NoRouteToHostException: No route to host: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
... 3 more
Caused by: java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.
at java.net.Socket.
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 9 more
jndi.properties路径错误
javax.naming.NameNotFoundException: com.lyh.compute.Counter not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.compute.Client.main(Client.java:18)
jndi.properties路径错误
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.compute.Client.main(Client.java:17)
javax.naming.NameNotFoundException: com.lyh.compute.Counter not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.compute.Client.main(Client.java:17)
Counter counter = (Counter) ctx.lookup("ComputeEJB");
Exception in thread "main" java.lang.ClassCastException: org.jnp.interfaces.NamingContext
at com.lyh.compute.Client.main(Client.java:18)
Counter counter = (Counter) ctx.lookup("java:comp/env/ComputeEJB");
javax.naming.NameNotFoundException: comp not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.compute.Client.main(Client.java:18)
常见问题处理
当运行ConverterClient 时发现下面错误:
1. java.lang.ClassCastException
可能无法找到ConverterAppClient.jar文件。
2. java.lang.NoClassDefFoundError: ConverterClient
无法定位ConverterClient.class 文件。
3. java.lang.NoClassDefFoundError: javax/naming/Context
无法找到所需的j2ee.jar 文件,确认CLASSPATH设置。
4. javax.naming.NameNotFoundException: Lookup of name MyConverter failed.
J2EE服务器无法定位JNDI名字MyConverter所绑定的组件。
5. javax.naming.NamingException: Error accessing repository: Cannot connect to ORB at . . . .
J2EE服务器没有运行。
加入Standalone Jar包
Exception in thread "main" javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: org.jboss.mq.referenceable.ObjectRefAddr (no security manager: RMI class loader disabled)]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb3.clients.JmsClient_ReservationProducer.main(JmsClient_ReservationProducer.java:40)
Caused by: java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: org.jboss.mq.referenceable.ObjectRefAddr (no security manager: RMI class loader disabled)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
... 3 more
Caused by: java.lang.ClassNotFoundException: org.jboss.mq.referenceable.ObjectRefAddr (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
... 6 more
注意:本异常中在Jboss控制台在有相关无状态会话Bean的正确部署信息。
去掉StandAlone包,
出现错误语句:
DataAccess access =(DataAccess)jndiContext.lookup("DataAccessBean/remote");
Exception in thread "main" javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.ejb3.stateless.StatelessRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 2583299153931800023, local class serialVersionUID = -9097306519795868]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:723)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb3.clients.JmsClient_ReservationProducer.main(JmsClient_ReservationProducer.java:32)
Caused by: java.io.InvalidClassException: org.jboss.ejb3.stateless.StatelessRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 2583299153931800023, local class serialVersionUID = -9097306519795868
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:653)
... 3 more
强制类型转换出错
log4j:WARN No appenders could be found for logger (org.jboss.security.SecurityAssociation).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ClassCastException: org.jboss.mq.SpyConnection
at com.lyh.ejb3.clients.JmsClient_ReservationProducer.main(JmsClient_ReservationProducer.java:58)
缺少standalone的三个Jar包
Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference
at com.lyh.ejb3.clients.Client.main(Client.java:40)
缺少配置文件内容如下:此文件任意取名,与jndi.properties文件在相同目录下
22:14:45,843 INFO [Ejb3DescriptorHandler] adding class annotation javax.ejb.Mes
sageDriven to com.lyh.ejb3.mdb.ExampleMDB org.jboss.ejb.MessageDrivenImpl@1ec3fe
d
22:14:45,859 INFO [Ejb3DescriptorHandler] adding class annotation javax.ejb.Tra
nsactionManagement to com.lyh.ejb3.mdb.ExampleMDB org.jboss.ejb.TransactionManag
ementImpl@ed55ec
22:14:45,859 INFO [Ejb3Deployment] EJB3 deployment time took: 1281
22:14:45,968 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=MDBDe
ploymentdescriptor.jar,name=ExampleMDB,service=EJB3 with dependencies:
22:14:46,187 INFO [EJBContainer] STARTED EJB: com.lyh.ejb3.mdb.ExampleMDB ejbNa
me: ExampleMDB
22:14:46,515 INFO [EJB3Deployer] Deployed: file:/D:/jbossGA/server/all/deploy/M
DBDeploymentdescriptor.jar
Exception in thread "main" javax.naming.NameNotFoundException: tutorial not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb3.clients.Client.main(Client.java:40)
缺少StandAlone的三个Jar包
customer Bill Burker
Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/jboss/invocation/Invoker;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredField(Unknown Source)
at java.io.ObjectStreamClass.getDeclaredSUID(Unknown Source)
at java.io.ObjectStreamClass.access$700(Unknown Source)
at java.io.ObjectStreamClass$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.
at java.io.ObjectStreamClass.lookup(Unknown Source)
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:107)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279)
at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
at org.jboss.remoting.Client.invoke(Client.java:525)
at org.jboss.remoting.Client.invoke(Client.java:488)
at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:34)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:46)
at $Proxy1.createProxy(Unknown Source)
at org.jboss.ejb3.JndiProxyFactory.getObjectInstance(JndiProxyFactory.java:52)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1125)
at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1142)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:705)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lyh.ejb3.clients.TravelAgentShell.getAgent(TravelAgentShell.java:46)
at com.lyh.ejb3.clients.TravelAgentShell.customer(TravelAgentShell.java:156)
at com.lyh.ejb3.clients.TravelAgentShell.processCommand(TravelAgentShell.java:115)
at com.lyh.ejb3.clients.TravelAgentShell.shell(TravelAgentShell.java:83)
at com.lyh.ejb3.clients.TravelAgentShell.main(TravelAgentShell.java:36)
Hibernate EntityManager 文档描述如下:
If no persistence.xml with the correct
name are found or if the expected persistence provider is not found, a PersistenceException is raised.
数据库没有启动时会出现如下异常,persistence.xml配置错误也会出现,如帐户,密码错误
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at com.titan.clients.StandaloneClient.main(StandaloneClient.java:16)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:397)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
... 3 more
加入JBOSS的jboss-EJB-3.0_Embeddable_ALPHA_8中的jar包即可
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named titan
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:41)
at com.lyh.ejb3.clients.StandaloneClient.main(StandaloneClient.java:21)
在数据库中插入字段,并抛出异常
public Integer getId() {
return this.id;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public void setId(Integer id) {
this.id = id;
}
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.lyh.ejb3.domain.Book
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:227)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:398)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
数据库中存在相同记录
Exception in thread "main" java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SWEETY/28, BranchQual=, localId=28] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)
at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:297)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:190)
at org.jboss.remoting.Client.invoke(Client.java:525)
at org.jboss.remoting.Client.invoke(Client.java:488)
at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:133)
at $Proxy1.createCabin(Unknown Source)
at com.lyh.ejb3.clients.Client_1.main(Client_1.java:33)
Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SWEETY/28, BranchQual=, localId=28] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
at org.jboss.tm.TxManager.commit(TxManager.java:240)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:297)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
Caused by: javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:555)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:484)
at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
... 23 more
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
... 26 more
Caused by: java.sql.BatchUpdateException: Duplicate entry '1' for key 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:656)
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:517)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 33 more