<insert id="insert" parameterType="MyPojo" useGeneratedKeys="true" keyColumn="primary_key" keyProperty="id"> INSERT INTO some_table (port_number) VALUES ( <dynamic> <isEqual property="portNumber" compareValue="0"> null </isEqual> <isNotEqual property="portNumber" compareValue="0"> #portNumber# </isNotEqual> </dynamic> ) </insert>