You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by nepalon <in...@163.com> on 2008/04/11 04:48:20 UTC

Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

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.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
I have tried the code and it work well:
Connection cn1 = null;
		PreparedStatement pst1 = null;
		PreparedStatement pst2 = null;
		ResultSet rs1 = null; 
		ResultSet rs2 = null; 
		DataSource ds = (BasicDataSource)ctx.getBean("cmsDbcpDataSource");
		
		try
		{
			cn1 = ds.getConnection();
	        pst1 = cn1.prepareStatement("select fid, fname, fcategoryid from
t_softwares");
	        rs1 = pst1.executeQuery();
	        while(rs1.next())
	        {
	        	System.out.println("software:" + rs1.getString(2));
	        	pst2 = cn1.prepareStatement("select fid, fname from t_categories
where fid=?");
	        	pst2.setInt(1, rs1.getInt(3));
		        rs2 = pst2.executeQuery();
		        if(rs2.next())
		        {
		        	System.out.println("category:" + rs2.getString(2));
		        }
				rs2.close();
				pst2.close();
	        }
			rs1.close();
			pst1.close();
			cn1.close();
	        
		}
		catch(Exception e)
		{
			e.printStackTrace();
			assertTrue(false);
		}

Jeff Butler-2 wrote:
> 
> Your JDBC code does not match what iBATIS is doing.  Try this:
> 
> try {
>   cn = ds.getConnection();
>   pst1 = cn.prepareStatement("select * from t_softwares");
>   rs1 = pst1.executeQuery();
>   while(rs1.next()) {
>     System.out.println("software:" + rs1.getString(1));
>     pst2 = cn.prepareStatement("select * from t_categories");
>     rs2 = pst2.executeQuery();
>     while(rs2.next()) {
>       System.out.println("category:" + rs2.getString(1));
>     }
>     rs2.close();
>     pst2.close();
>   }
>   rs1.close();
>   pst1.close();
> }
> Jeff Butler
> 
> 
> On Tue, Apr 15, 2008 at 10:36 PM, nepalon <in...@163.com> wrote:
> 
>>
>> I try the code and it work well.At first, I get Connection using
>> DriverManager and work well.I think the bug maybe cause by DataSource
>> that
>> return Connection from pool,so I try to get Connection using
>> DataSource,but
>> it work well too.So I still believe the exception causing by iBatis.
>>
>> Connection cn = null;
>>                PreparedStatement pst1 = null;
>>                PreparedStatement pst2 = null;
>>                ResultSet rs1 = null;
>>                ResultSet rs2 = null;
>>                DataSource ds =
>> (BasicDataSource)ctx.getBean("cmsDbcpDataSource");
>>
>>                try
>>                {
>> //
>>  Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
>> //              cn =
>>
>> DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/macconverter",
>> "sa", "iloveyou");
>>                        cn = ds.getConnection();
>>                pst1 = cn.prepareStatement("select * from t_softwares");
>>                rs1 = pst1.executeQuery();
>>                while(rs1.next())
>>                {
>>                        System.out.println("software:" +
>> rs1.getString(1));
>>                }
>>                pst2 = cn.prepareStatement("select * from t_categories");
>>                rs2 = pst2.executeQuery();
>>                while(rs2.next())
>>                {
>>                        System.out.println("category:" +
>> rs2.getString(1));
>>                }
>>                }
>>                catch(Exception e)
>>                {
>>                        e.printStackTrace();
>>                        assertTrue(false);
>>                }
>>                finally
>>                {
>>                        try {
>>                                rs1.close();
>>                                rs2.close();
>>                                pst1.close();
>>                                pst2.close();
>>                                cn.close();
>>                        }
>>                        catch (SQLException e)
>>                        {
>>                         }
>>                }
>>
>> Larry Meadors wrote:
>> >
>> > Google for "sql 2005 HY010 jdbc -db2", and you'll get more info - it
>> > looks like you're not the first person to get this error, but I didn't
>> > see anything that led me to believe that this is a bug in iBATIS -
>> > more likely an issue with the driver, possibly configuration.
>> >
>> > Try simplifying the mapped statement and/or doing the query with JDBC
>> > instead and see what happens.
>> >
>> > Larry
>> >
>> >
>> > On Mon, Apr 14, 2008 at 11:46 PM, nepalon <in...@163.com> wrote:
>> >>
>> >>  I am sure my DB is configured to allow more than one ResultSet
>> open.As
>> >> you
>> >>  see in the above code, the code CategoryModel model =
>> >>  categoryDao.getCategoryById(273) I code can work well.The code will
>> load
>> >> the
>> >>  category object the id is 273 and its parent category object whick
>> the
>> >> id is
>> >>  270.In this code,more than one ResultSet was open.
>> >>
>> >>
>> >>
>> >>
>> >>  Jeff Butler-2 wrote:
>> >>  >
>> >>  > I once had a similar problem with DB2.  The problem was that the DB
>> >> was
>> >>  > configured to allow only one open ResultSet per connection.
>> >>  >
>> >>  > With your query, you will have more than one open ResultSet - so
>> make
>> >> sure
>> >>  > your DB is configured to allow this.
>> >>  >
>> >>  > Jeff Butler
>> >>  >
>> >>  > On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:
>> >>  >
>> >>  >>
>> >>  >> The DB i using is SQL Server2005.The error string(HY010) means
>> >> "Invalid
>> >>  >> state, the ResultSet object is closed".Somebody says this error
>> cause
>> >> by
>> >>  >> using miscrosoft sql server driver,but I using jtds as my dirver.
>> >>  >>
>> >>  >> Larry Meadors wrote:
>> >>  >> >
>> >>  >> > This looks like a DB2 issue, you may want to search for that
>> error
>> >>  >> > string (HY010), I think that's probably going to get you a
>> solution
>> >>  >> > quickest.
>> >>  >> >
>> >>  >> > Larry
>> >>  >> >
>> >>  >> >
>> >>  >>
>> >>  >> --
>> >>  >> 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-tp16624071p16656703.html
>> >>  >>  Sent from the iBATIS - User - Java mailing list archive at
>> >> Nabble.com.
>> >>  >>
>> >>  >>
>> >>  >
>> >>  >
>> >>
>> >>  --
>> >>  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-tp16624071p16695510.html
>> >>
>> >>
>> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> 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-tp16624071p16715819.html
>>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
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-tp16624071p16737591.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Jeff Butler <je...@gmail.com>.
Your JDBC code does not match what iBATIS is doing.  Try this:

try {
  cn = ds.getConnection();
  pst1 = cn.prepareStatement("select * from t_softwares");
  rs1 = pst1.executeQuery();
  while(rs1.next()) {
    System.out.println("software:" + rs1.getString(1));
    pst2 = cn.prepareStatement("select * from t_categories");
    rs2 = pst2.executeQuery();
    while(rs2.next()) {
      System.out.println("category:" + rs2.getString(1));
    }
    rs2.close();
    pst2.close();
  }
  rs1.close();
  pst1.close();
}
Jeff Butler


On Tue, Apr 15, 2008 at 10:36 PM, nepalon <in...@163.com> wrote:

>
> I try the code and it work well.At first, I get Connection using
> DriverManager and work well.I think the bug maybe cause by DataSource that
> return Connection from pool,so I try to get Connection using
> DataSource,but
> it work well too.So I still believe the exception causing by iBatis.
>
> Connection cn = null;
>                PreparedStatement pst1 = null;
>                PreparedStatement pst2 = null;
>                ResultSet rs1 = null;
>                ResultSet rs2 = null;
>                DataSource ds =
> (BasicDataSource)ctx.getBean("cmsDbcpDataSource");
>
>                try
>                {
> //
>  Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
> //              cn =
>
> DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/macconverter",
> "sa", "iloveyou");
>                        cn = ds.getConnection();
>                pst1 = cn.prepareStatement("select * from t_softwares");
>                rs1 = pst1.executeQuery();
>                while(rs1.next())
>                {
>                        System.out.println("software:" + rs1.getString(1));
>                }
>                pst2 = cn.prepareStatement("select * from t_categories");
>                rs2 = pst2.executeQuery();
>                while(rs2.next())
>                {
>                        System.out.println("category:" + rs2.getString(1));
>                }
>                }
>                catch(Exception e)
>                {
>                        e.printStackTrace();
>                        assertTrue(false);
>                }
>                finally
>                {
>                        try {
>                                rs1.close();
>                                rs2.close();
>                                pst1.close();
>                                pst2.close();
>                                cn.close();
>                        }
>                        catch (SQLException e)
>                        {
>                         }
>                }
>
> Larry Meadors wrote:
> >
> > Google for "sql 2005 HY010 jdbc -db2", and you'll get more info - it
> > looks like you're not the first person to get this error, but I didn't
> > see anything that led me to believe that this is a bug in iBATIS -
> > more likely an issue with the driver, possibly configuration.
> >
> > Try simplifying the mapped statement and/or doing the query with JDBC
> > instead and see what happens.
> >
> > Larry
> >
> >
> > On Mon, Apr 14, 2008 at 11:46 PM, nepalon <in...@163.com> wrote:
> >>
> >>  I am sure my DB is configured to allow more than one ResultSet open.As
> >> you
> >>  see in the above code, the code CategoryModel model =
> >>  categoryDao.getCategoryById(273) I code can work well.The code will
> load
> >> the
> >>  category object the id is 273 and its parent category object whick the
> >> id is
> >>  270.In this code,more than one ResultSet was open.
> >>
> >>
> >>
> >>
> >>  Jeff Butler-2 wrote:
> >>  >
> >>  > I once had a similar problem with DB2.  The problem was that the DB
> >> was
> >>  > configured to allow only one open ResultSet per connection.
> >>  >
> >>  > With your query, you will have more than one open ResultSet - so
> make
> >> sure
> >>  > your DB is configured to allow this.
> >>  >
> >>  > Jeff Butler
> >>  >
> >>  > On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:
> >>  >
> >>  >>
> >>  >> The DB i using is SQL Server2005.The error string(HY010) means
> >> "Invalid
> >>  >> state, the ResultSet object is closed".Somebody says this error
> cause
> >> by
> >>  >> using miscrosoft sql server driver,but I using jtds as my dirver.
> >>  >>
> >>  >> Larry Meadors wrote:
> >>  >> >
> >>  >> > This looks like a DB2 issue, you may want to search for that
> error
> >>  >> > string (HY010), I think that's probably going to get you a
> solution
> >>  >> > quickest.
> >>  >> >
> >>  >> > Larry
> >>  >> >
> >>  >> >
> >>  >>
> >>  >> --
> >>  >> 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-tp16624071p16656703.html
> >>  >>  Sent from the iBATIS - User - Java mailing list archive at
> >> Nabble.com.
> >>  >>
> >>  >>
> >>  >
> >>  >
> >>
> >>  --
> >>  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-tp16624071p16695510.html
> >>
> >>
> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> 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-tp16624071p16715819.html
>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
I try the code and it work well.At first, I get Connection using
DriverManager and work well.I think the bug maybe cause by DataSource that
return Connection from pool,so I try to get Connection using DataSource,but
it work well too.So I still believe the exception causing by iBatis.

Connection cn = null;
		PreparedStatement pst1 = null;
		PreparedStatement pst2 = null;
		ResultSet rs1 = null; 
		ResultSet rs2 = null; 
		DataSource ds = (BasicDataSource)ctx.getBean("cmsDbcpDataSource");
		
		try
		{
//			Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
//	        cn =
DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/macconverter",
"sa", "iloveyou");
			cn = ds.getConnection();
	        pst1 = cn.prepareStatement("select * from t_softwares");
	        rs1 = pst1.executeQuery();
	        while(rs1.next())
	        {
	        	System.out.println("software:" + rs1.getString(1));
	        }
	        pst2 = cn.prepareStatement("select * from t_categories");
	        rs2 = pst2.executeQuery();
	        while(rs2.next())
	        {
	        	System.out.println("category:" + rs2.getString(1));
	        }
		}
		catch(Exception e)
		{
			e.printStackTrace();
			assertTrue(false);
		}
		finally
		{
			try {
				rs1.close();
				rs2.close();
				pst1.close();
				pst2.close();
				cn.close();
			} 
			catch (SQLException e) 
			{
			}
		}

Larry Meadors wrote:
> 
> Google for "sql 2005 HY010 jdbc -db2", and you'll get more info - it
> looks like you're not the first person to get this error, but I didn't
> see anything that led me to believe that this is a bug in iBATIS -
> more likely an issue with the driver, possibly configuration.
> 
> Try simplifying the mapped statement and/or doing the query with JDBC
> instead and see what happens.
> 
> Larry
> 
> 
> On Mon, Apr 14, 2008 at 11:46 PM, nepalon <in...@163.com> wrote:
>>
>>  I am sure my DB is configured to allow more than one ResultSet open.As
>> you
>>  see in the above code, the code CategoryModel model =
>>  categoryDao.getCategoryById(273) I code can work well.The code will load
>> the
>>  category object the id is 273 and its parent category object whick the
>> id is
>>  270.In this code,more than one ResultSet was open.
>>
>>
>>
>>
>>  Jeff Butler-2 wrote:
>>  >
>>  > I once had a similar problem with DB2.  The problem was that the DB
>> was
>>  > configured to allow only one open ResultSet per connection.
>>  >
>>  > With your query, you will have more than one open ResultSet - so make
>> sure
>>  > your DB is configured to allow this.
>>  >
>>  > Jeff Butler
>>  >
>>  > On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:
>>  >
>>  >>
>>  >> The DB i using is SQL Server2005.The error string(HY010) means
>> "Invalid
>>  >> state, the ResultSet object is closed".Somebody says this error cause
>> by
>>  >> using miscrosoft sql server driver,but I using jtds as my dirver.
>>  >>
>>  >> Larry Meadors wrote:
>>  >> >
>>  >> > This looks like a DB2 issue, you may want to search for that error
>>  >> > string (HY010), I think that's probably going to get you a solution
>>  >> > quickest.
>>  >> >
>>  >> > Larry
>>  >> >
>>  >> >
>>  >>
>>  >> --
>>  >> 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-tp16624071p16656703.html
>>  >>  Sent from the iBATIS - User - Java mailing list archive at
>> Nabble.com.
>>  >>
>>  >>
>>  >
>>  >
>>
>>  --
>>  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-tp16624071p16695510.html
>>
>>
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
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-tp16624071p16715819.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Larry Meadors <la...@gmail.com>.
Google for "sql 2005 HY010 jdbc -db2", and you'll get more info - it
looks like you're not the first person to get this error, but I didn't
see anything that led me to believe that this is a bug in iBATIS -
more likely an issue with the driver, possibly configuration.

Try simplifying the mapped statement and/or doing the query with JDBC
instead and see what happens.

Larry


On Mon, Apr 14, 2008 at 11:46 PM, nepalon <in...@163.com> wrote:
>
>  I am sure my DB is configured to allow more than one ResultSet open.As you
>  see in the above code, the code CategoryModel model =
>  categoryDao.getCategoryById(273) I code can work well.The code will load the
>  category object the id is 273 and its parent category object whick the id is
>  270.In this code,more than one ResultSet was open.
>
>
>
>
>  Jeff Butler-2 wrote:
>  >
>  > I once had a similar problem with DB2.  The problem was that the DB was
>  > configured to allow only one open ResultSet per connection.
>  >
>  > With your query, you will have more than one open ResultSet - so make sure
>  > your DB is configured to allow this.
>  >
>  > Jeff Butler
>  >
>  > On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:
>  >
>  >>
>  >> The DB i using is SQL Server2005.The error string(HY010) means "Invalid
>  >> state, the ResultSet object is closed".Somebody says this error cause by
>  >> using miscrosoft sql server driver,but I using jtds as my dirver.
>  >>
>  >> Larry Meadors wrote:
>  >> >
>  >> > This looks like a DB2 issue, you may want to search for that error
>  >> > string (HY010), I think that's probably going to get you a solution
>  >> > quickest.
>  >> >
>  >> > Larry
>  >> >
>  >> >
>  >>
>  >> --
>  >> 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-tp16624071p16656703.html
>  >>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>  >>
>  >>
>  >
>  >
>
>  --
>  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-tp16624071p16695510.html
>
>
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
I am sure my DB is configured to allow more than one ResultSet open.As you
see in the above code, the code CategoryModel model =
categoryDao.getCategoryById(273) I code can work well.The code will load the
category object the id is 273 and its parent category object whick the id is
270.In this code,more than one ResultSet was open.


Jeff Butler-2 wrote:
> 
> I once had a similar problem with DB2.  The problem was that the DB was
> configured to allow only one open ResultSet per connection.
> 
> With your query, you will have more than one open ResultSet - so make sure
> your DB is configured to allow this.
> 
> Jeff Butler
> 
> On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:
> 
>>
>> The DB i using is SQL Server2005.The error string(HY010) means "Invalid
>> state, the ResultSet object is closed".Somebody says this error cause by
>> using miscrosoft sql server driver,but I using jtds as my dirver.
>>
>> Larry Meadors wrote:
>> >
>> > This looks like a DB2 issue, you may want to search for that error
>> > string (HY010), I think that's probably going to get you a solution
>> > quickest.
>> >
>> > Larry
>> >
>> >
>>
>> --
>> 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-tp16624071p16656703.html
>>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
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-tp16624071p16695510.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Jeff Butler <je...@gmail.com>.
I once had a similar problem with DB2.  The problem was that the DB was
configured to allow only one open ResultSet per connection.

With your query, you will have more than one open ResultSet - so make sure
your DB is configured to allow this.

Jeff Butler

On Sat, Apr 12, 2008 at 10:47 PM, nepalon <in...@163.com> wrote:

>
> The DB i using is SQL Server2005.The error string(HY010) means "Invalid
> state, the ResultSet object is closed".Somebody says this error cause by
> using miscrosoft sql server driver,but I using jtds as my dirver.
>
> Larry Meadors wrote:
> >
> > This looks like a DB2 issue, you may want to search for that error
> > string (HY010), I think that's probably going to get you a solution
> > quickest.
> >
> > Larry
> >
> >
>
> --
> 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-tp16624071p16656703.html
>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
The DB i using is SQL Server2005.The error string(HY010) means "Invalid
state, the ResultSet object is closed".Somebody says this error cause by
using miscrosoft sql server driver,but I using jtds as my dirver.

Larry Meadors wrote:
> 
> This looks like a DB2 issue, you may want to search for that error
> string (HY010), I think that's probably going to get you a solution
> quickest.
> 
> Larry
> 
> 

-- 
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-tp16624071p16656703.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Larry Meadors <la...@gmail.com>.
This looks like a DB2 issue, you may want to search for that error
string (HY010), I think that's probably going to get you a solution
quickest.

Larry

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
I have try ibatis version 2.3.0.677 and 2.3.1.710,spring version 2.0.7 and
2.5.3.
-- 
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-tp16624071p16645060.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by viren1 <vi...@modius.com>.
I am having the same exact problem after upgrading iBATIS from 2.2.0.638 to
2.3.0.677 and keeping the DAO package version 2.2.0.638. I don't have this
problem with iBATIS 2.2.0.638 version at all.
We are using JTDS 1.2.2 and MSSQL 2005.
Any suggestions?
thx.


nepalon 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);
>          }
> }
> 
> It is no problem with loading category using categoryDao,such as
> CategoryModel model = categoryDao.getCategoryById(273).
> But if load a software using "SoftwareModel model =
> softwareDao.getSoftwareById(111)" or "SoftwareModel model =
> softwareDao.getSoftwareByName("aaa");",it will throw exception showing in
> the end of the message.And if I remove the config “<result
> property="parentCategory" column="FParentID"
> select="Category.getCategoryById" />” in the file Category.xml,he code
> 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
> 
> Somebody guess it cause by the DB configurate.I test the code,but I did
> not find any exception.
> Connection cn1 = null;
> 		PreparedStatement pst1 = null;
> 		PreparedStatement pst2 = null;
> 		ResultSet rs1 = null; 
> 		ResultSet rs2 = null; 
> 		DataSource ds = (BasicDataSource)ctx.getBean("cmsDbcpDataSource");
> 		
> 		try
> 		{
> //			Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
> //	        cn1 =
> DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/test",
> "sa", "aa");
> 			cn1 = ds.getConnection();
> 	        pst1 = cn1.prepareStatement("select fid, fname, fcategoryid from
> t_softwares");
> 	        rs1 = pst1.executeQuery();
> 	        while(rs1.next())
> 	        {
> 	        	System.out.println("software:" + rs1.getString(2));
> 	        	pst2 = cn1.prepareStatement("select fid, fname from t_categories
> where fid=?");
> 	        	pst2.setInt(1, rs1.getInt(3));
> 		        rs2 = pst2.executeQuery();
> 		        if(rs2.next())
> 		        {
> 		        	System.out.println("category:" + rs2.getString(2));
> 		        }
> 				rs2.close();
> 				pst2.close();
> 	        }
> 			rs1.close();
> 			pst1.close();
> 			cn1.close();
> 	        
> 		}
> 		catch(Exception e)
> 		{
> 			e.printStackTrace();
> 			assertTrue(false);
> 		}
> 
> 

-- 
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-tp16624071p17566308.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Brandon Goodin <br...@gmail.com>.
Which specific version of iBATIS are you using?

Brandon Goodin

On Thu, Apr 10, 2008 at 9:48 PM, nepalon <in...@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.
>
>

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Clinton Begin <cl...@gmail.com>.
This error happens when your JDBC driver or database does not allow multiple
cursors to be open at the same time within one connection.  I've seen it
before.  It's usually a simple matter of finding the correct settings to
pass to your JDBC driver (on the db url) to allow multiple cursors (or
cursors at all).  I'm not sure what they are for jtds, but for SQL Server
it's selectMode=cursor.

Clinton



On Wed, Apr 23, 2008 at 3:26 AM, nepalon <in...@163.com> wrote:

>
> Who can help me?I am crazy in the question.
> --
> 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-tp16624071p16833562.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by Nicholoz Koka Kiknadze <ki...@gmail.com>.
I noticed there are only two tables involved, could you try with some
different database engine ? If you still get similar exception, one should
start inspecting your code/iBatis code, if not, definitely it's a driver/db
server problem (try different driver)...

Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed

Posted by nepalon <in...@163.com>.
Who can help me?I am crazy in the question.
-- 
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-tp16624071p16833562.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.