ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed
Date Fri, 11 Apr 2008 13:34:27 GMT
Which specific version of iBATIS are you using?

Brandon Goodin

On Thu, Apr 10, 2008 at 9:48 PM, nepalon <inepalon@163.com> wrote:

>
> There are two class.:
> public class CategoryModel implements Serializable
> {
>         private int id;
>
>         private String name;
>
>         private int parentCategoryId;
>
>         private CategoryModel parentCategory;
>
>         // setter/getter
>         ......
> }
>
> public class SoftwareModel implements Serializable
> {
>         private int id;
>
>         private String name;
>
>         private CategoryModel category;
>
>         // setter/getter
>         ......
> }
>
> The xml config file of ibatis:
> <sqlMapConfig>
>         <settings
>                   cacheModelsEnabled="true"
>                   enhancementEnabled="true"
>                   lazyLoadingEnabled="true"
>                   useStatementNamespaces="true"/>
>
>       <sqlMap resource="com/demo/category/Category.xml"/>
>       <sqlMap resource="com/demo/software/Software.xml"/>
> </sqlMapConfig>
>
> Category.xml
> <sqlMap namespace="Category">
>
>         <typeAlias alias="category"
>                   type="com.demo.category.model.CategoryModel" />
>
>         <cacheModel type="OSCACHE" id="category-cache">
>                   <flushInterval minutes="10" />
>                   <flushOnExecute statement="Category.addCartory"/>
>         </cacheModel>
>
>         <resultMap class="category" id="categoryResult">
>                   <result property="id" column="FID" javaType="int"
> jdbcType="int"
>                            nullValue="0" />
>                   <result property="name" column="FName" javaType="String"
>                            jdbcType="nvarchar" />
>                   <result property="parentCategoryId" column="FParentID"
> javaType="int" jdbcType="int"
>                            nullValue="0" />
>                   <!-- TODO:this line config will cause throwing exception
> when call softwareDao.getSoftwareById -->
>                   <result property="parentCategory" column="FParentID"
> select="Category.getCategoryById" />
>         </resultMap>
>
>         <select id="getCategoryById" resultMap="categoryResult"
>                   parameterClass="int" cacheModel="category-cache">
>                   SELECT * FROM t_categories
>                   WHERE FID =#categoryId#
>         </select>
> </sqlMap>
>
> Software.xml
> <sqlMap namespace="Software">
>
>         <typeAlias alias="software"
>                   type="com.demo.software.model.SoftwareModel" />
>
>         <cacheModel type="OSCACHE" id="software-cache">
>                   <flushInterval minutes="10" />
>                   <flushOnExecute statement="Software.addSoftware"/>
>         </cacheModel>
>
>         <resultMap class="software" id="softwareResult">
>                   <result property="id" column="FID" javaType="int"
> jdbcType="int"
>                            nullValue="0" />
>                   <result property="name" column="FName" javaType="String"
>                            jdbcType="nvarchar" />
>                   <result property="category" column="FCategoryID"
> select="Category.getCategoryById" />
>         </resultMap>
>
>         <select id="getSoftwareById" resultMap="softwareResult"
>                   parameterClass="int" cacheModel="software-cache">
>                   SELECT * FROM t_softwares
>                   WHERE FID =#softwareId#
>         </select>
>
>         <select id="getSoftwareByName" resultMap="softwareResult"
>                   parameterClass="string" cacheModel="software-cache">
>                   SELECT * FROM t_softwares
>                   WHERE FName =#name#
>         </select>
> </sqlMap>
>
> Use ibatis with springframwork:
> <beans
>         xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
>
>         <bean id="messageProperties"
>
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>                   <property name="locations">
>                            <list>
>
> <value>classpath:properties/cms.properties</value>
>                            </list>
>                   </property>
>         </bean>
>
>         <bean id="cmsDbcpDataSource"
> class="org.apache.commons.dbcp.BasicDataSource">
>                   <property name="driverClassName">
>
>  <value>${cms.datasource.driverClassName}</value>
>                   </property>
>                   <property name="url">
>                            <value>${cms.datasource.url}</value>
>                   </property>
>                   <property name="username">
>                            <value>${cms.datasource.username}</value>
>                   </property>
>                   <property name="password">
>                            <value>${cms.datasource.password}</value>
>                   </property>
>         </bean>
>
>         <bean id="cmsSqlMapClient"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>                   <property name="configLocation">
>                            <value>classpath:cms-sql-map-config.xml</value>
>                   </property>
>                   <property name="dataSource">
>                            <ref bean="cmsDbcpDataSource"/>
>                   </property>
>         </bean>
>
>         <bean id="cmsSqlMapClientTemplete"
> class="org.springframework.orm.ibatis.SqlMapClientTemplate">
>                   <property name="sqlMapClient">
>                            <ref bean="cmsSqlMapClient"/>
>                   </property>
>         </bean>
>
>         <bean id="transactionManager"
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>                   <property name="dataSource">
>                            <ref local="cmsDbcpDataSource" />
>                   </property>
>         </bean>
>
>         <bean id="baseTxProxy" lazy-init="true"
>
> class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
> abstract="true">
>                   <property name="transactionManager">
>                            <ref local="transactionManager" />
>                   </property>
>                   <property name="transactionAttributes">
>                            <props>
>                                     <prop
> key="*">PROPAGATION_REQUIRED</prop>
>                                     <prop
> key="create*">PROPAGATION_REQUIRED</prop>
>                                     <prop
> key="add*">PROPAGATION_REQUIRED</prop>
>                                     <prop
> key="delete*">PROPAGATION_REQUIRED</prop>
>                                     <prop
> key="update*">PROPAGATION_REQUIRED</prop>
>                                     <prop
> key="get*">PROPAGATION_REQUIRED</prop>
>                            </props>
>                   </property>
>         </bean>
>
>         <bean id="categoryDao"
>
> class="com.demo.category.dao.impl.ibatis.CategoryDaoImpl">
>                   <property name="cmsSqlMapClientTemplete">
>                            <ref bean="cmsSqlMapClientTemplete" />
>                   </property>
>         </bean>
>
>         <bean id="softwareDao"
>
> class="com.demo.software.dao.impl.ibatis.SoftwareDaoImpl">
>                   <property name="cmsSqlMapClientTemplete">
>                            <ref bean="cmsSqlMapClientTemplete" />
>                   </property>
>         </bean>
> </beans>
>
> This is the class:
> public abstract class BaseDaoImpl
> {
>         private SqlMapClientTemplate cmsSqlMapClientTemplete;
>
>         public SqlMapClientTemplate getCmsSqlMapClientTemplete()
>         {
>                   return cmsSqlMapClientTemplete;
>         }
>
>         public void setCmsSqlMapClientTemplete(
>                            SqlMapClientTemplate cmsSqlMapClientTemplete)
>         {
>                   this.cmsSqlMapClientTemplete = cmsSqlMapClientTemplete;
>         }
> }
>
> public class SoftwareDaoImpl extends BaseDaoImpl implements SoftwareDao
> {
>
>         @Override
>         public SoftwareModel getSoftwareById(int softwareId)
>         {
>                   return (SoftwareModel)
> getCmsSqlMapClientTemplete().queryForObject("Software.getSoftwareById",
> new
> Integer(softwareId));
>         }
>
>         @Override
>         public SoftwareModel getSoftwareByName(String name)
>         {
>                   return (SoftwareModel)
> getCmsSqlMapClientTemplete().queryForObject("Software.getSoftwareByName",
> name);
>         }
> }
>
> public class CategoryDaoImpl extends BaseDaoImpl implements CategoryDao
> {
>
>         @Override
>         public CategoryModel getCategoryById(int categoryId)
>         {
>                   return (CategoryModel)
> getCmsSqlMapClientTemplete().queryForObject("Category.getCategoryById",
> new
> Integer(categoryId));
>         }
>
>         @Override
>         public CategoryModel getCategoryByName(String name)
>         {
>                   return (CategoryModel)
> getCmsSqlMapClientTemplete().queryForObject("Category.getCategoryByName",
> name);
>         }
> }
>
> Under code will cause throwing exception show in the end:
> SoftwareModel model = softwareDao.getSoftwareById(111);//throw exception
> SoftwareModel model = softwareDao.getSoftwareByName("aaa");// throw
> exception
> If I remove the config "<result property="parentCategory"
> column="FParentID"
> select="Category.getCategoryById" />" in the file Category.xml.The code
> will
> not throw exception.
> But curiously, the code "CategoryModel model =
> categoryDao.getCategoryById(273)" will not throw exception.
> It is the stack with exception:
> org.springframework.jdbc.UncategorizedSQLException: SqlMapClient
> operation;
> uncategorized SQLException for SQL []; SQL state [HY010]; error code [0];
> --- The error occurred in com/demo/software/Software.xml.
> --- The error occurred while applying a result map.
> --- Check the Software.softwareResult.
> --- Check the result mapping for the 'category' property.
> --- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/category/Category.xml.
> --- The error occurred while applying a result map.
> --- Check the Category.categoryResult.
> --- The error happened while setting a property on the result object.
> --- Cause: java.sql.SQLException: Invalid state, the ResultSet object is
> closed.; nested exception is
> com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/software/Software.xml.
> --- The error occurred while applying a result map.
> --- Check the Software.softwareResult.
> --- Check the result mapping for the 'category' property.
> --- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/category/Category.xml.
> --- The error occurred while applying a result map.
> --- Check the Category.categoryResult.
> --- The error happened while setting a property on the result object.
> --- Cause: java.sql.SQLException: Invalid state, the ResultSet object is
> closed.
>         at
>
> org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:124)
>         at
>
> org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
>         at
>
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
>         at
>
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
>         at
>
> com.shareweb.cms.component.software.dao.impl.ibatis.SoftwareDaoImpl.getSoftwareById(SoftwareDaoImpl.java:23)
>         at
>
> com.shareweb.cms.importdata.AdvertExcelImportManagerImplTest.testImportData(AdvertExcelImportManagerImplTest.java:54)
>         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 junit.framework.TestCase.runTest(TestCase.java:154)
>         at junit.framework.TestCase.runBare(TestCase.java:127)
>         at junit.framework.TestResult$1.protect(TestResult.java:106)
>         at junit.framework.TestResult.runProtected(TestResult.java:124)
>         at junit.framework.TestResult.run(TestResult.java:109)
>         at junit.framework.TestCase.run(TestCase.java:118)
>         at junit.framework.TestSuite.runTest(TestSuite.java:208)
>         at junit.framework.TestSuite.run(TestSuite.java:203)
>         at
>
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>         at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/software/Software.xml.
> --- The error occurred while applying a result map.
> --- Check the Software.softwareResult.
> --- Check the result mapping for the 'category' property.
> --- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/category/Category.xml.
> --- The error occurred while applying a result map.
> --- Check the Category.categoryResult.
> --- The error happened while setting a property on the result object.
> --- Cause: java.sql.SQLException: Invalid state, the ResultSet object is
> closed.
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.CachingStatement.executeQueryForObject(CachingStatement.java:79)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
>         at
>
> org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
>         at
>
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
>         ... 21 more
> Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in com/demo/category/Category.xml.
> --- The error occurred while applying a result map.
> --- Check the Category.categoryResult.
> --- The error happened while setting a property on the result object.
> --- Cause: java.sql.SQLException: Invalid state, the ResultSet object is
> closed.
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.CachingStatement.executeQueryForObject(CachingStatement.java:79)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
>         at
>
> com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
>         at
>
> com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:75)
>         at
>
> com.ibatis.sqlmap.engine.mapping.result.loader.LazyResultLoader.loadResult(LazyResultLoader.java:77)
>         at
>
> com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.loadResult(ResultLoader.java:54)
>         at
>
> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getNestedSelectMappingValue(ResultMap.java:501)
>         at
>
> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:341)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>         ... 28 more
> Caused by: java.sql.SQLException: Invalid state, the ResultSet object is
> closed.
>         at
> net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299)
>         at
> net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:569)
>         at
>
> org.apache.commons.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:169)
>         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.ibatis.common.jdbc.logging.ResultSetLogProxy.invoke(ResultSetLogProxy.java:47)
>         at $Proxy10.next(Unknown Source)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:383)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>         at
>
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>         at
>
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>         ... 44 more
>
> --
> View this message in context:
> http://www.nabble.com/Problem-in-resultMap%3ACause%3A-java.sql.SQLException%3A-Invalid-state%2C-the-ResultSet-object-is-closed-tp16624071p16624071.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Mime
View raw message