出现java.io.NotSerializableException错误。

来源:互联网 发布:中学生网络方式挣钱 编辑:程序博客网 时间:2024/05/16 08:33

最近参与了使用JAVA语言开发的项目,开发环境是MyEclipse + WebLogic。

自己也发了几个帖子介绍了一下使用到的一些技术。

如何在JAVA程序中使用Struct一次传入多条数据给Oracle的存储过程。

如何以Collection变量作为数据源来向数据表中插入数据,或者更新数据。

如何在Oracle中修改Collection类型的变量。

如何在Oracle中向Collection类型的变量中逐条插入数据。

但是在进行UT的时候下面的代码无法通过。

StructDescriptor st = new StructDescriptor("DEPARTMENT_TYPE",dbConn);

出现的错误是:

Caused by: java.rmi.MarshalException: error marshalling return; nested exception is: 
    java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection
    at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:195)

出现这样问题的原因都是有对象没有进行序列化。我们出现这个问题的现象是:进行UT时程序无法运行,但是从JSP页面进行调用就没有问题。所以分析的结果是我们写的项目架构中用于UT的部分没有继承序列化或者Struct本身没有继承序列化。

参考:

http://forums.bea.com/thread.jspa?messageID=600034901&tstart=0
http://forums.bea.com/thread.jspa?messageID=400006195
http://e-docs.bea.com/wls/docs81/jdbc/thirdparty.html#1043705
http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1054307
//******************************************************************************************
To obtain a connection for a JDBC client, use a Java Naming and Directory Interface (JDNI) lookup to locate the DataSource object, as shown in the following code fragment.
Note: When using a JDBC connection in a client-side application, the exact same JDBC driver classes must be in the CLASSPATH on both the server and the client. If the driver classes do not match, you may see java.rmi.UnmarshalException exceptions.
//******************************************************************************************