I am working on Spring-Hibernate-Websphere application and sybase as database. Following is the code snippet to configure Spring/Hibernate to refer to JNDI datasource of Websphere.
<?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"/>
Here are the values for the properties used in above code:
hibernate.dialect=org.hibernate.dialect.SybaseDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.connection.autocommit=false
hibernate.max_fetch_depth=0
Above configuration works fine while using some simple queries, and I can see those hibernate generated queries on console. However, while executing some complex queries (with multiple joins), I find exception cased by below exception.
[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)
What may be causing this error? Any pointers greatly appreciated.
The problem was resolved with the installation of the Websphere Fixpack 7.0.0.13+ (We installed 7.0.0.21). The problem lied in handling of the getUpdateCount() from websphere. When a prepared statement is created (in our case by Hibernate), and before execution, if getUpdateCount() is called, Syabase (and informix as per IBM support), throws SQLException while other databases simply return -1. This was not handled from Websphere and the exeception was propogated to the application code. With the fixpack, this is handled and problem is resolved.
More reading here