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: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared statement found. This is likely a bug.
Date Thu, 16 Nov 2006 14:21:11 GMT
>From what i can see of your code you are trying to use iBATIS in more of an
Active Record fashion. With iBATIS it is not a good idea to make database
calls from within your domain beans. As a general practice, it is best to
operate on your domain beans externally either by providing information to
the bean at instantiation(not supported in iBATIS) or via a getter/setter
(supported). An enhanced route to go for using the setter is to setup a
resultMap that can populate a complex type. This would essentially be using
the setter. Since you expose your setter and getter. I would recommend that
you use a result map.

As a side note I noticed you were using <statement> for all of your mapped
statements... there are others available as well <procedure>, <select>,
<insert>, <update>, <delete>. There are variations between them that provide
more focused control over the type of database call and return type.

Hope that helps,
Brandon Goodin

On 11/15/06, Peter Andrews <peter.andrews@dartmouth.edu> wrote:
>
>  I am sorry but I don't have the time to distill everything to a nice
> example. My guess is that it easy to replicate by following my essential
> (possibly poor) technique which is that the setter for one of my resultClass
> properties makes another call to the db via iBATIS (see the setGeneKey
> method in GeneExperimentResult.java).
>
> As I read more about iBATIS, I realize the more conventional way to
> accomplish what I want is to use a resultMap with Complex Properties such
> that a returned foreignKey to another class retrieves that class. I did not
> do so because I think it is more complicated, particularly given that I am
> not using any resultMaps since my column names and bean names match exactly.
>
> Brandon Goodin wrote:
>
> Please post your code involved in producing this. Post sqlmap config, dao
> java code, and bean java code.
>
> Brandon
>
> On 11/14/06, Peter Andrews < peter.andrews@dartmouth.edu> wrote:
> >
> > I am sorry if this has been discussed previously -- the mail archives
> > seem to be currently unavailable (get network connection error).
> >
> > I am getting an error. The error message is different between 2.2.0 and
> > the subversion latest. The error in the subject line is from the
> > subversion code. In the 2.2.0 I get:
> >
> > com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Result consisted of
> > more than one row
> >
> > When the message says 'This is likely a bug' does it mean a bug in
> > iBATIS or a bug in my code? I think it means iBATIS.
> >
> > At the bottom of this email is a partial stack trace (the full trace
> > goes on for a very long time repeating itself and ends with  '...30
> > more').
> >
> > I think the issue is that one of my calls into iBATIS can cause
> > additional calls to occur before the first one ends. This is because
> > some of my setter functions also make calls to the db.
> >
> > 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 stack trace:
> > run-single:
> > DEBUG: iBATIS SqlMap for db 'GeneDataset' initialized
> > DEBUG: queryForObject 'getResearcherByUsername' passing: PeterVermont
> > DEBUG: queryForObject 'getResearcherByUsername' returning:
> > org.epistasis.db.geneExperiment.Researcher[id=1]
> > DEBUG: queryForList 'getGeneExperimentResultsByDatasetExperimentId'
> > passing: 1   <==*********************NOTE: Still in process when when
> > following calls start
> > DEBUG: queryForObject 'getGeneKeyById' passing: 1
> > DEBUG: queryForObject 'getGeneKeyById' returning:
> > org.epistasis.db.geneExperiment.GeneKey[id=1]
> > DEBUG: queryForObject 'getGeneKeyById' passing:
> > 2
> > <==*********************NOTE: second call to getGeneKeyById since
> >
> >
> >
> > 'getGeneExperimentResultsByDatasetExperimentId' started
> > 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.
> > Caused by: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
> > statement found.  This is likely a bug.
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(
> > GeneralStatement.java:188)
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject
> > (GeneralStatement.java:104)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject (
> > SqlMapExecutorDelegate.java:566)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(
> > SqlMapExecutorDelegate.java:541)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject (
> > SqlMapSessionImpl.java:106)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(
> > SqlMapClientImpl.java:83)
> >         at
> > org.epistasis.db.SqlMapClientWrapper.queryForObject(
> > SqlMapClientWrapper.java :21)
> >         at
> > org.epistasis.db.geneDataset.GeneDatasetDbAccess.getGeneKeyById(
> > GeneDatasetDbAccess.java:94)
> >         at
> > org.epistasis.db.geneDataset.GeneKey.getGeneKeyById(GeneKey.java:49)
> >         at
> > org.epistasis.db.geneDataset.GeneExperimentResult.setGeneKeyId (
> > GeneExperimentResult.java:110)
> >         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:585)
> >         at
> > com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(
> > PropertyAccessPlan.java:46)
> >         at
> > com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(
> > JavaBeanDataExchange.java:115)
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues
> > (BasicResultMap.java:373)
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject
> > (RowHandlerCallback.java:64)
> > ERROR: Caught an exception
> >         at
> > com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(
> > SqlExecutor.java:377)
> >         at
> > com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(
> > SqlExecutor.java:296)
> >         at
> > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(
> > SqlExecutor.java :187)
> > com.ibatis.common.jdbc.exception.RuntimeSQLException:
> > com.ibatis.common.jdbc.exception.NestedSQLException:
> > --- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
> > --- The error occurred while applying a result map.
> > --- Check the
> > getGeneExperimentResultsByDatasetExperimentId-AutoResultMap.
> > --- The error happened while setting a property on the result object.
> > --- Cause: java.lang.RuntimeException: Error setting property
> > 'setGeneKeyId' of
> > 'org.epistasis.db.geneExperiment.GeneExperimentResult[id=2]'.  Cause:
> > com.ibatis.common.jdbc.exception.RuntimeSQLException:
> > 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.
> > Caused by: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
> > statement found.  This is likely a bug.
> > Caused by: java.lang.RuntimeException: Error setting property
> > 'setGeneKeyId' of
> > 'org.epistasis.db.geneExperiment.GeneExperimentResult[id=2]'.  Cause:
> > com.ibatis.common.jdbc.exception.RuntimeSQLException:
> > com.ibatis.common.jdbc.exception.NestedSQLException:
> > --- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
> > --- The error occurred while executing query.
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery
> > (GeneralStatement.java:205)
> > --- Check the      CALL getGeneKeyById(?)   .
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback
> > (GeneralStatement.java:173)
> > --- Check the SQL Statement (preparation failed).
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(
> > GeneralStatement.java:123)
> > --- Cause: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
> > statement found.  This is likely a bug.
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList (
> > SqlMapExecutorDelegate.java:615)
> > Caused by: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
> > statement found.  This is likely a bug.
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList (
> > SqlMapExecutorDelegate.java:589)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(
> > SqlMapSessionImpl.java:118)
> >         at
> > org.epistasis.db.SqlMapClientWrapper.queryForList(
> > SqlMapClientWrapper.java :50)
> >         at
> > com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(
> > SqlMapClientImpl.java:95)
> >         at
> >
> > org.epistasis.db.geneDataset.GeneDatasetDbAccess.getGeneExperimentResultsByDatasetExperimentId
> > (GeneDatasetDbAccess.java :90)
> >         at
> > org.epistasis.db.SqlMapClientWrapper.queryForList(
> > SqlMapClientWrapper.java:45)
> >         at
> > org.epistasis.db.geneDataset.GeneDatasetDbAccess.main(
> > GeneDatasetDbAccess.java:167)
> >         at
> >
> > org.epistasis.db.geneDataset.GeneDatasetDbAccess.getGeneExperimentResultsByDatasetExperimentId(
> > GeneDatasetDbAccess.java:90)
> > Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
> >         at
> > org.epistasis.db.geneDataset.GeneDatasetDbAccess.main(
> > GeneDatasetDbAccess.java:167)
> > --- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
> > Caused by: com.ibatis.sqlmap.client.SqlMapException: Duplicate prepared
> > statement found.  This is likely a bug.
> > --- The error occurred while applying a result map.
> >         at
> > com.ibatis.sqlmap.engine.scope.SessionScope.putPreparedStatement (
> > SessionScope.java:247)
> > --- Check the
> > getGeneExperimentResultsByDatasetExperimentId-AutoResultMap.
> >         at
> > com.ibatis.sqlmap.engine.execution.SqlExecutor.prepareStatement(
> > SqlExecutor.java:488)
> > --- The error happened while setting a property on the result object.
> >         at
> > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(
> > SqlExecutor.java:173)
> > --- Cause: java.lang.RuntimeException: Error setting property
> > 'setGeneKeyId' of
> > 'org.epistasis.db.geneExperiment.GeneExperimentResult [id=2]'.  Cause:
> > com.ibatis.common.jdbc.exception.RuntimeSQLException:
> > com.ibatis.common.jdbc.exception.NestedSQLException:
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(
> > GeneralStatement.java:205)
> > --- The error occurred in org/epistasis/db/geneDataset/GeneDataset.xml.
> >         at
> >
> > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback
> > (GeneralStatement.java :173)
> > --- The error occurred while executing query.
> >         ... 30 more
> >
> > --
> > Peter Andrews
> > Software Engineer
> > Dartmouth Medical School
> > Computational Genetics
> > Rubin 707
> > (603) 653-3598
> > Peter.Andrews@dartmouth.edu
> >
> >
>
> --
> Peter Andrews
> Software Engineer
> Dartmouth Medical School
> Computational Genetics
> Rubin 707
> (603) 653-3598
> Peter.Andrews@dartmouth.edu
>
>
>

Mime
View raw message