ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Iwao AVE!" <haraw...@gmail.com>
Subject Re: mysql default value
Date Wed, 18 Mar 2009 15:14:56 GMT
Hi Alin,

How about using <isNotNull /> or <isNotEmpty />?

<insert id="insertExample" parameterClass="com.test.Example">
 INSERT INTO vjobs (
  name, status
  <isNotNull property="description" prepend=",">
   description
  </isNotNull>
 ) VALUES (
  #name#, #status#
  <isNotNull property="description" prepend=",">
   #description#
  </isNotNull>
 )
</insert>

I haven't tested this, but it should work.

Regards,
Iwao

on 09.3.18 9:42 PM Alin Popa said the following:
> Thanks Nicholoz,
> 
> This is what I've done. And I also have a facade that will abstract
> for the user, the insert actions.
> I thought that ibatis knows how to handle this, or have a trick for it.
> 
> On Wed, Mar 18, 2009 at 10:51 AM, Nicholoz Koka Kiknadze
> <kiknadze@gmail.com> wrote:
>>> Why don't you just exclude this field in the <insert>?
>> <insert id="insertExampleWithDefaults" parameterClass="com.test.
>> Example">
>>  INSERT INTO vjobs(name, description) VALUES
>> (#name#,#description#)
>> </insert>
>>
>> GL
>>
>>
>>
>> IMO because sometimes one need to insert NULL values too. So why don't you
>> add another insert statement to your xml that will omit the status field?
>>
>> On Wed, Mar 18, 2009 at 4:19 AM, Kengkaj Sathianpantarit
>> <kengkaj.s@gmail.com> wrote:
>>> However, I think that default value is good in the case that we don't need
>>> to specify value in INSERT command.
>>> Why don't you just exclude this field in the <insert>?
>>>
>>> For <update>, I think that we should specify value explicitly in the
>>> model, error from database is correct behavior in case the field has null
>>> value (actually this is the reason why we set NOT NULL constraint).
>>>
>>> Kengkaj
>>>
>>>
>>> On Wed, Mar 18, 2009 at 3:06 PM, Alin Popa <alin.popa@gmail.com> wrote:
>>>> Thanks Kengkaj,
>>>>
>>>> But from what I read it seems that nullValue is used to substitute
>>>> value with a database NULL.
>>>> The thing is that I'm not allowed to use null since field is "NOT NULL".
>>>>
>>>>
>>>> On Wed, Mar 18, 2009 at 6:00 AM, Kengkaj Sathianpantarit
>>>> <kengkaj.s@gmail.com> wrote:
>>>>> Use null value replacement feature, read user manual.
>>>>>
>>>>> Kengkaj
>>>>>
>>>>> On Tue, Mar 17, 2009 at 10:37 PM, Alin Popa <alin.popa@gmail.com>
>>>>> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have the following db table (MySQL):
>>>>>>
>>>>>> CREATE TABLE `examples`(
>>>>>>        `id` SERIAL PRIMARY KEY,
>>>>>>        `name` VARCHAR(255),
>>>>>>        `status` VARCHAR(20) NOT NULL DEFAULT 'ready',
>>>>>>        `description` TEXT
>>>>>> ) ENGINE=innodb DEFAULT CHARSET utf8 DEFAULT COLLATE utf8_bin;
>>>>>>
>>>>>>
>>>>>> Using ibatis sql-map I'm doing this:
>>>>>>
>>>>>> <insert id="insertExample" parameterClass="com.test.Example">
>>>>>>  INSERT INTO vjobs(name, status, description) VALUES
>>>>>> (#name#,#status#,#description#)
>>>>>> </insert>
>>>>>>
>>>>>> When inserting an example object, without having "status" field set,
I
>>>>>> got Column 'status' cannot be null; but the DEFAULT is 'ready'.
>>>>>>
>>>>>> How can this be managed using ibatis ?
>>>>>> It is possible ?
>>>>>>
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> Alin
>>>>>
>>>>
>>>>
>>>> --
>>>> Best Regards,
>>>>
>>>> Alin


Mime
View raw message