Hello,

I have a simple insert query like this (I am sure that at least one of the properties is not empty)

<insert id="insertItem" parameterClass="item">
 INSERT INTO ITEMS_TABLE
 (
 <dynamic>
<isNotEmpty prepend="," property="propertyOne" removeFirstPrepend="true">
     PROPERTY_ONE
   </isNotEmpty>
<isNotEmpty prepend="," property="propertyTwo" removeFirstPrepend="true">
     PROPERTY_TWO
   </isNotEmpty>
 </dynamic>
 ,
 VALUE
 )
 VALUES
 (
 <dynamic>
<isNotEmpty prepend="," property="propertyOne" removeFirstPrepend="true">
     #propertyOne#
   </isNotEmpty>
<isNotEmpty prepend="," property="propertyTwo" removeFirstPrepend="true">
     #propertyTwo#
   </isNotEmpty>
 </dynamic>
 ,
 #value:NUMERIC#
 )
</insert>

The generated String for the prepared statement will be like this in the case of when both of the properties are not empty:

INSERT INTO ITEMS_TABLE ( , PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES ( , ? , ? , ? )

So the 1st prepend is not being removed.
I have done a workaround for it by specifying the prepend attribute for the <dynamic> element:

 <dynamic prepend="(">

Then it worked fine:

INSERT INTO ITEMS_TABLE ( PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES ( ? , ? , ? )

I just wonder, is it normal?
Because I find the 'prepend="("' thing a bit ugly, and I would like to have it like in my example.



Thanks in advance and respect

Pye

Reply via email to