ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neilhe...@f2s.com
Subject Re: Parameter Maps AND dynamic sql at the same time
Date Fri, 28 Oct 2005 13:43:38 GMT
Hi

In the iBatis-SqlMaps-2.pdf (page 16) it states:

Note! Dynamic mapped statements (described below) only support inline parameters
and do not work with
parameter maps.

Regards
Neil

Quoting g m <gazj2ee@yahoo.co.uk>:

> Well spotted - it appears I pasted the wrong xml
> fragment. My mistake.
> Here's the correct one, along with the parameter map
> I'm using.
>
> <insert id="insertSupplierExtras"
> parameterMap="SupplierExtrasParam">
> 	insert into <dynamic><isEqual property="status"
> compareValue="1">supplierextrastm</isEqual><isEqual
> property="status"
> compareValue="0">supplierextras</isEqual></dynamic>
> 	( preferredsupplier, contactname, websiteaddress,
> companyregno, emailaddress, supplier) values (?, ?, ?,
> ?, ?, ?)</insert>
>
>
> <parameterMap class="SupplierIF"
> id="SupplierExtrasParam">
> 		<parameter property="preferredSupplier"
>
typeHandler="com.phones4u.datamanagement.datamodel.ibatis.typehandler.SmallIntBooleanTypeHandler"/>
> 		<parameter property="contactName" />
> 		<parameter property="webAddress"/>
> 		<parameter property="companyRegistrationNumber" />
> 		<parameter property="emailAddress"/>
> 		<parameter property="code"/>
> 	</parameterMap>
>
> I've just tried it again to confirm the error (I
> played around with it a lot trying to get it to work,
> so I wanted to make sure that this sql fragment is
> definitely being called) and the error stops happening
> if I remove the <dynamic> element from the <insert>,
> giving me this debug output:
>
>
> DEBUG [AWT-EventQueue-0] - {pstm-100017}
> PreparedStatement:   insert into supplierextrastm  (
> preferredsupplier, contactname, websiteaddress,
> companyregno, emailaddress, supplier) values (?, ?, ?,
> ?, ?, ?)
> DEBUG [AWT-EventQueue-0] - {pstm-100017} Parameters:
> [1, c, , c, , C]
> DEBUG [AWT-EventQueue-0] - {pstm-100017} Types:
> [java.lang.Short, java.lang.String, java.lang.String,
> java.lang.String, java.lang.String, java.lang.String]
>
>
> Cheers,
> Gareth.
>
> PS Apologies for the huge disclaimer - the legal
> department at my company have far too much time on
> their hands.
> --- Larry Meadors <lmeadors@apache.org> wrote:
>
> > There is something else going wrong here..
> >
> > In the stack trace, it shows this message:
> > "Check the
> > Supplier.insertSupplierExtras-InlineParameterMap"
> >
> > That tells me that you were running
> > "insertSupplierExtras" with an inline
> > parameter map.
> >
> > But the statement sent was "updateSupplierExtras"
> > with an explicit parameter
> > map.
> >
> > I know that dynamic SQL and parameter maps work, so
> > I think we are missing
> > some pieces of the puzzle here.
> >
> > Larry
> >
> >
> > PS: Can you please trim the massive disclaimer, or
> > use another account when
> > posting? GMail is free, and works great for this
> > stuff.
> >
> >
> > On 10/28/05, Gareth Moorst
> > <Gareth.Moorst@phones4u.co.uk> wrote:
> > >
> > > I'm trying to write insert/update statements that
> > can have their table
> > > dynamically altered, but I'm having problems with
> > any statements that use
> > > parameter maps...
> > >
> > > <update id="updateSupplierExtras"
> > parameterMap="SupplierExtrasParam">
> > > update <dynamic><isEqual property="status"
> > >
> > compareValue="1">supplierextrastm</isEqual><isEqual
> > property="status"
> > >
> > compareValue="0">supplierextras</isEqual></dynamic>
> > set
> > > preferredsupplier = ?,
> > > contactname = ?,
> > > websiteaddress = ?,
> > > companyregno = ?,
> > > emailaddress=?
> > > where supplier=?
> > > </update>
> > >
> > > If I use inline parameters, then I don't have a
> > problem, but when I try to
> > > use either a <dynamic> clause or a $tableName$
> > clause in the map, I get this
> > > error :
> > >
> > >
> > > DEBUG [AWT-EventQueue-0] - {pstm-100017}
> > PreparedStatement: insert into
> > > supplierextrastm ( preferredsupplier, contactname,
> > websiteaddress,
> > > companyregno, emailaddress, supplier) values (?,
> > ?, ?, ?, ?, ?)
> > > DEBUG [AWT-EventQueue-0] - {pstm-100017}
> > Parameters: []
> > > DEBUG [AWT-EventQueue-0] - {pstm-100017} Types: []
> > > WARN [AWT-EventQueue-0] - Error saving supplier
> > >
> > org.springframework.jdbc.UncategorizedSQLException:
> > SqlMapClient
> > > operation; uncategorized SQLException for SQL [];
> > SQL state [IX000]; error
> > > code [-79749];
> > > --- The error occurred while applying a parameter
> > map.
> > > --- Check the
> > Supplier.insertSupplierExtras-InlineParameterMap.
> > > --- Check the statement (update failed).
> > > --- Cause: java.sql.SQLException: Number of input
> > values does not match
> > > number of question marks;
> > >
> > > Looking at the trace, it seems that when I use any
> > form of dynamic sql,
> > > none of the parameters are passed. Is this the
> > correct behaviour? Is it
> > > possible to use dynamic sql and parameter maps at
> > the same time?
> > >
> > > I'm using iBatis 2.1.5.
> > >
> > > Cheers,
> > > Gareth Moorst
> > >
> > >
> >
>
>
>
>
>
>
> ___________________________________________________________
> Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with
> voicemail http://uk.messenger.yahoo.com
>




Mime
View raw message