我正在使用Spring-Hibernate-Websphere应用程序和sybase作为数据库。以下是配置Spring / Hibernate以引用Websphere的JNDI数据源的代码片段。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/icpDS" />
<property name="lookupOnStartup" value="false" />
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.ubs.research.icp.hibernate.object" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
以下是上述代码中使用的属性的值:
hibernate.dialect=org.hibernate.dialect.SybaseDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.connection.autocommit=false
hibernate.max_fetch_depth=0
上面的配置在使用一些简单的查询时工作正常,我可以在控制台上看到那些hibernate生成的查询。但是,在执行一些复杂查询(具有多个连接)时,我发现由以下异常引发的异常。
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R Caused by: java.sql.SQLException: JZ0PA: The query has been cancelled and the response discarded. The cancel was probably issued by another statement on the connection.
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at com.sybase.jdbc3.jdbc.SybStatement.getUpdateCount(Unknown Source)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:479)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:240)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:193)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:534)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:269)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:285)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:212)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.Loader.doQuery(Loader.java:726)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.Loader.doList(Loader.java:2213)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.Loader.list(Loader.java:2099)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
[6/25/12 13:31:00:357 EDT] 0000002f SystemErr R at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
可能导致此错误的原因是什么?任何指针都非常感激。
答案 0 :(得分:0)
通过安装Websphere Fixpack 7.0.0.13+(我们安装了7.0.0.21)解决了这个问题。问题在于从websphere处理getUpdateCount()。当创建预准备语句时(在我们的例子中是Hibernate),并且在执行之前,如果调用了getUpdateCount(),则Syabase(以及根据IBM支持的informix)抛出SQLException,而其他数据库只返回-1。这不是从Websphere处理的,并且exeception被传播到应用程序代码。使用fixpack,可以解决问题并解决问题。
更多阅读here