java.sql.SQLException: 违反协议,OALL8 处于不一致状态

今天OMS后代报出了一些异常,java.sql.SQLException: 违反协议,OALL8 处于不一致状态。整个应用都不能用,重启一下就好了。第一次出异常的地方为
[OMS][2011-02-12 20:51:57 312] ERROR [TP-Processor11] JDBCTransaction.rollback(168) | JDBC rollback failed
java.sql.SQLException: 违反协议
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:150)
at oracle.jdbc.driver.T4CConnection.doRollback(T4CConnection.java:567)
at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1136)
at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:265)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:288)
at org.hibernate.transaction.JDBCTransaction.rollbackAndResetAutoCommit(JDBCTransaction.java:183)
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:162)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:625)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionMan
ager.java:800)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.ja
va:777)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSu
pport.java:339)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy40.updateNodeNetByIdPath(Unknown Source)
at com.wondertek.mobiletv.oms.webapp.action.NodeAction.linkNodeToSpecNode(NodeAction.java:476)
at sun.reflect.GeneratedMethodAccessor1520.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.wondertek.mobiletv.oms.webapp.interceptor.AppLogInterceptor.intercept(AppLogInterceptor.java:124)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.jav
a:48)


网上说提交的数据类型长度大于数据库或者说是数据库驱动允许的最大值,就会出现上述错误。通过com.wondertek.mobiletv.oms.webapp.action.NodeAction.linkNodeToSpecNode(NodeAction.java:476查找相当操作日志。

6	760793	resNodeNetId=32946,,destiNodeNetId=56320,,flag=contMenu_linkToNode,	NodeAction -- linknodetospecnode	12-FEB-11 08.51.53.001000 PM		0	2420
7 760826 resNodeNetId=32946,,destiNodeNetId=56320,,flag=contMenu_linkToNode, NodeAction -- linknodetospecnode 12-FEB-11 08.51.49.725000 PM 0 2420
8 760824 resNodeNetId=31786,,destiNodeNetId=56320,,flag=contMenu_linkToNode, NodeAction -- linknodetospecnode 12-FEB-11 08.51.23.817000 PM 0 2420
9 760792 resNodeNetId=31786,,destiNodeNetId=56320,,flag=contMenu_linkToNode, NodeAction -- linknodetospecnode 12-FEB-11 08.51.05.918000 PM 0 2420
相关源节点
1 56320 12-FEB-11 08.50.18.776000 PM /68581/90961 0 /3列首页/全能看 68581 11 /mainbycol/qnk 2 90961
没有找到相关源节点32946


网上的解释。
[quote]在系统使用过程中后台偶尔报上述错误;系统部署环境:linux操作系统,JBOSS作应用服务器,数据库Oracle9i,用的Oracle驱动class12(是针对oracle10g的)。
具体的异常信息如下:
Caused by: java.sql.SQLException: OALL8 处于不一致状态
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.T4C8Oall.marshal(T4C8Oall.java:352)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:202)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1037)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3361)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 88 more
伴随其他异常信息:
java.sql.SQLException: 违反协议
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:150)
at oracle.jdbc.driver.T4CConnection.doCommit(T4CConnection.java:523)
at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1128)
at org.apache.commons.dbcp.DelegatingConnection.commit(DelegatingConnection.java:238)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.commit(PoolingDataSource.java:199)
at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager

124 JDBC commit failed
java.sql.SQLException: 类型长度大于最大值
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.T4CMAREngine.buffer2Value(T4CMAREngine.java:2493)
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB2(T4CMAREngine.java:1177)
at oracle.jdbc.driver.T4CTTIoer.unmarshal(T4CTTIoer.java:126)
at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:134)
at oracle.jdbc.driver.T4CConnection.doCommit(T4CConnection.java:523)
at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1128)
javax.servlet.ServletException: Java heap space

分析异常原因:
1.首先用的Oracle数据版本9i和使用的数据库驱动jar包 (class12 for Oracle10g)不一致;
2. 在1的前提下,如果你提交的数据类型长度大于数据库或者说是数据库驱动允许的最大值,就会出现上述错误。
网上最好的英文原版异常原因分析:
This is known to occur under when you are using too big an array size. How big your array can be depends on the length of each record and the Driver/Database combination.
If you exceed the maximum size you will get the "OALL8" SQLException and your connection object may become unusable.

Java call pl/sql 时如果使用 array 参数,则需要使用
oracler的特定语法--描述符. 

一个描述符对象代表了pl/sql中的一个 array type.

获取一个 描述符对象 需要使用 oracle.jdbc.OracleConnection.

[/quote]


这个分析的比较透彻
[quote]一次做应用升级出现了一个问题,描述如下:
升级分为两块,一块是数据库结构变更(表结构增加新字段);一块是应用程序的升级。
应用环境为:jboss4.0.5 + ibatis + spring 数据源在jboss的oracle-ds.xml文件中进行配置,通过spring的jndi方式进行查找 。
我先将数据库进行升级,更改表结构(增加字段),因为应用中的ibatis的查询采用的是ResultMap返回方式,返回定义的表结构字段,即使数据库发生变更,也不会产生影响。于是我大胆的进行脚本的执行。结果当我下午16:00数据库变更之后,几乎在同时就有人反应应用的一些查询功能无法使用,立刻查看出错日志:
Java代码

1. Caused by: com.alibaba.generalorm.dao.DataAccessException: Data query error!
2. --- The error occurred in sqlmap/CiaDissension.xml.
3. --- The error occurred while applying a parameter map.
4. --- Check the QUERY_ALL_DISSENSION_CATEGORY-InlineParameterMap.
5. --- Check the statement (query failed).
6. --- Cause: java.sql.SQLException: OALL8 处于不一致状态
7. at com.alibaba.ibatis.BasicIBatisDao.query(BasicIBatisDao.java:315)
8. at com.alibaba.china.rcc.riskdc.dao.DissensionCategoryDAO.getAll(DissensionCategoryDAO.java:40)
9. at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getCategoryMap(DissensionServiceImpl.java:495)
10. at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getCategory(DissensionServiceImpl.java:188)
11. at com.alibaba.china.rcc.riskdc.web.action.DissensionAction.getCategory(DissensionAction.java:263)
12. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
15. at java.lang.reflect.Method.invoke(Method.java:597)
16. at com.alibaba.webx.action.invoker.AbstractModuleMethodInvoker.executeNoArgMethod(AbstractModuleMethodInvoker.java:401)
17. ... 33 more

Caused by: com.alibaba.generalorm.dao.DataAccessException: Data query error!
--- The error occurred in sqlmap/CiaDissension.xml.
--- The error occurred while applying a parameter map.
--- Check the QUERY_ALL_DISSENSION_CATEGORY-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: OALL8 处于不一致状态
at com.alibaba.ibatis.BasicIBatisDao.query(BasicIBatisDao.java:315)
at com.alibaba.china.rcc.riskdc.dao.DissensionCategoryDAO.getAll(DissensionCategoryDAO.java:40)
at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getCategoryMap(DissensionServiceImpl.java:495)
at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getCategory(DissensionServiceImpl.java:188)
at com.alibaba.china.rcc.riskdc.web.action.DissensionAction.getCategory(DissensionAction.java:263)
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:597)
at com.alibaba.webx.action.invoker.AbstractModuleMethodInvoker.executeNoArgMethod(AbstractModuleMethodInvoker.java:401)
... 33 more


Java代码

1. Caused by: com.alibaba.generalorm.dao.DataAccessException: Data query error!
2. --- The error occurred in sqlmap/CiaDissension.xml.
3. --- The error occurred while applying a parameter map.
4. --- Check the QUERY_ALL_DISSENSION_BUSINESS-InlineParameterMap.
5. --- Check the statement (query failed).
6. --- Cause: java.sql.SQLException: 违反协议
7. at com.alibaba.ibatis.BasicIBatisDao.query(BasicIBatisDao.java:315)
8. at com.alibaba.china.rcc.riskdc.dao.DissensionBusinessDAO.getAll(DissensionBusinessDAO.java:19)
9. at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getBusiness(DissensionServiceImpl.java:178)
10. at com.alibaba.china.rcc.riskdc.web.action.DissensionAction.getBusiness(DissensionAction.java:249)
11. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
13. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
14. at java.lang.reflect.Method.invoke(Method.java:597)
15. at com.alibaba.webx.action.invoker.AbstractModuleMethodInvoker.executeNoArgMethod(AbstractModuleMethodInvoker.java:401)
16. ... 33 more

Caused by: com.alibaba.generalorm.dao.DataAccessException: Data query error!
--- The error occurred in sqlmap/CiaDissension.xml.
--- The error occurred while applying a parameter map.
--- Check the QUERY_ALL_DISSENSION_BUSINESS-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: 违反协议
at com.alibaba.ibatis.BasicIBatisDao.query(BasicIBatisDao.java:315)
at com.alibaba.china.rcc.riskdc.dao.DissensionBusinessDAO.getAll(DissensionBusinessDAO.java:19)
at com.alibaba.china.rcc.riskdc.service.impl.DissensionServiceImpl.getBusiness(DissensionServiceImpl.java:178)
at com.alibaba.china.rcc.riskdc.web.action.DissensionAction.getBusiness(DissensionAction.java:249)
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:597)
at com.alibaba.webx.action.invoker.AbstractModuleMethodInvoker.executeNoArgMethod(AbstractModuleMethodInvoker.java:401)
... 33 more


为什么会出现违反协议的问题?马上google一下,有些人说是因为数据库的字段类型与java中使用的类型不一致导致,但查看了ibtais的 map文件,老的应用代码根本还没有使用新的的字段!后来找pla共同排查,也没有发现应用程序哪里会出现问题,便打电话给DBA让他查下数据库,DBA 咨询了一位资格较老的DBA,他说以前也出现过这种情况,只要将应用重启下,就好了。马上重启,果然问题解决了,违反协议的错误没有再报。

查找原因:
在做升级前,我自己在开发环境也做过模拟,并没有出现如果应用不重启,数据库变更而报“违反协议”的错误。而我看了下发布环境与开发环境差异,唯一的差异是开发环境没有采用jboss+jndi的方式获取数据源,而采用了tomcat+c3p0的方式获取数据源。

于是我开始实验。
Tomcat+C3P0启动方式:
1.准备好更改数据库脚本。
2.在开发环境用tomcat启动应用,并访问到涉及表结构变更的页面。
3.执行数据库脚本,确保表结构发生了变更。
4.刷新在步骤2的页面,查看后台输出和前台页面输出。
5.一切正常,没有抛出违反协议或处于不一致状态的错误日志。
JBoss4.0.5+JNDI启动方式
1.准备好更改数据库脚本。
2.在开发环境用jboss启动应用,并访问到涉及表结构变更的页面。
3.执行数据库脚本,确保表结构发生了变更。
4.刷新在步骤2的页面,查看后台输出和前台页面输出。
5.出现了违反协议和处于不一致状态的问题。

总结:

由此可以看出,出现这个问题与ibatis没有关系,而与数据源的获取方式有关,一种是通过Spring+c3p0直接注入DataSource;一种是在oracle-ds.xml文件中配置,然后在spring中通过jndi的方式进行查找,获取数据源。第二种在数据库变更的情况下,就必须进行应用重启,否则就会抛出违反协议或处于不一致的状态。

但根本原因到底是什么呢?我还在寻找。
===================================================
咨询了大少,并不是因为数据源配置模式没有关系,用c3p0或者jndi等,而是与数据源的配置方式有关:

在oracle-ds的配置如下:
Java代码

1.
2. rccBopsDataSource
3. false
4. jdbc:oracle:thin:@xx.xx.xx.xx:1521:xx
5. true
6. 50
7. GBK
8. ISO-8859-1
9. com.alibaba.china.jdbc.SimpleDriver
10. 1
11. 14
12. 20
13.
14. Oracle9i
15.

16. 15
17. org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
18. xx
19. xx
20.



rccBopsDataSource
false
jdbc:oracle:thin:@xx.xx.xx.xx:1521:xx
true
50
GBK
ISO-8859-1
com.alibaba.china.jdbc.SimpleDriver
1
14
20

Oracle9i

15
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
xx
xx



其中prepared-statement-cache-size参数解释为:
- the number of prepared statements per connection to be kept open and reused in subsequent requests. They are stored in a LRU cache. The default is 0 (zero), meaning no cache.
为每个打开的数据库连接缓存了一定数量的prepared statement.他们是存在LRU cache中,如果设值为0,那么将不缓冲。这里我们设值了每个连接缓存20条prepared statment。

而在c3p0的配置中:
Xml代码

1. 2. class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
3.
4. com.mchange.v2.c3p0.DataSources.pooledDataSource
5.

6.
7.
8.
9.
10. 1
11. 1
12. 1
13. 5
14. 1800
15. 1000
16.
17.
18. 30
19. 1000
20. false
21.
22. 5000
23.

24.

25.

26. lt;/bean>

class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

com.mchange.v2.c3p0.DataSources.pooledDataSource





1
1
1
5
1800
1000


30
1000
false

5000






上网查了下,影响到preparedStatment cache的参数有两个:maxStatements和maxStatementsPerConnection 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭,默认为0。

继续实验:

1、将c3p0配置增加maxStatements和maxStatementsPerConnection并都设值20。
修改数据库表结构,刷新访问页面。
后台抛出违反协议和处于不一致状态的错误提示。

2.将oracle-ds.xml文件配置更改prepared-statement-cache-size为0。
修改数据库表结构,刷新访问页面。
后台没有抛出违反协议和处于不一致状态的错误提示。

附参考文章:

http://community.jboss.org/wiki/configdatasources 讲解jboss中关于datasource的参数
http://msq.iteye.com/blog/60387 讲解c3p0的详细参数
[/quote]
[url]http://www.iteye.com/topic/900077[/url]

你可能感兴趣的:(java综合)