ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Andrews <peter.andr...@Dartmouth.EDU>
Subject Caught exception: 'Duplicate prepared statement found. This is likely a bug.'
Date Thu, 16 Nov 2006 15:07:07 GMT
I posted a more complicated instance of this bug to the java user's
group but since I think it is an iBATIS bug here is again with
simplified description and test case.

I am running the current subversion code.

The basic issue is that if I have a complex resultMap that calls another
statement, the processing of the second object that is created gets a
duplicate prepared statement exception.

The iBATIS code that is throwing the exception is in SessionScope.java:
public void putPreparedStatement(String sql, PreparedStatement ps) {
   if (!isInBatch()) {
     if (hasPreparedStatementFor(sql))
       throw new SqlMapException("Duplicate prepared statement found.
This is likely a bug.");
     preparedStatements.put(sql, ps);

Changing the iBATIS code to:
     if (!hasPreparedStatementFor(sql))
       preparedStatements.put(sql, ps);

appears to fix the problem. I am an iBATIS novice user so is likely not
a correct fix (if the problem is even iBATIS').

Here is the relevant section of my sqlMap xml file:

   <resultMap id="resultMapGeneExperimentResult"
class="GeneExperimentResult" >
     <result property="id" column="id"/>
     <result property="geneKeyId" column="geneKeyId"/>
     <result property="geneKey" column="geneKeyId" select="getGeneKeyById"/>

<statement id="getGeneExperimentResultsByDatasetExperimentId"
parameterClass="Integer" resultMap="resultMapGeneExperimentResult">

  <statement id="getGeneKeyById"  parameterClass="Integer"
    CALL getGeneKeyById(#pGeneKeyId:NUMERIC#)

Here is the console output showing the objects being created and the

DEBUG: queryForList 'getGeneExperimentResultsByDatasetExperimentId'
passing: 1
DEBUG: org.epistasis.db.geneDataset.GeneKey created.
DEBUG: org.epistasis.db.geneDataset.GeneKey id set to: 1
DEBUG: org.epistasis.db.geneDataset.GeneExperimentResult created.
DEBUG: org.epistasis.db.geneDataset.GeneExperimentResult id set to: 1
--- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
--- The error occurred while applying a result map.
--- Check the GeneDataset.resultMapGeneExperimentResult.
--- Check the result mapping for the 'geneKey' property.
--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
--- The error occurred while executing query.
--- Check the      CALL getGeneKeyById(?)   .
--- Check the SQL Statement (preparation failed).
--- Cause: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
statement found.  This is likely a bug.

My SqlMapConfig is very unexceptional:
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"


  <!--NOTE: commitRequired must be true because iBATIS does not
recognize that a change has occurred and needs to be
          committed when I use stored procedures that do change the
database -->
  <transactionManager type="JDBC" commitRequired="true">
    <dataSource type="DBCP">
      <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
      <property name="JDBC.ConnectionURL"
      <property name="JDBC.Username" value="${geneDatasetDb.username}"/>
      <property name="JDBC.Password" value="${geneDatasetDb.password}"/>

  <!-- List the SQL Map XML files. They can be loaded from the
       classpath, as they are here (com.domain.data...) -->
  <sqlMap resource="org/epistasis/db/geneDataset/GeneDataset.xml"/>


Peter Andrews
Software Engineer
Dartmouth Medical School
Computational Genetics
Rubin 707
(603) 653-3598

View raw message