ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: mysql default value
Date Thu, 19 Mar 2009 13:41:45 GMT
On Wed, Mar 18, 2009 at 9:47 PM, Kengkaj Sathianpantarit
<kengkaj.s@gmail.com> wrote:
> Interesting, thanks.
> However, I think it's a bit ugly. And what about if we want to insert null
> value?

You can't:

       `status` VARCHAR(20) NOT NULL DEFAULT 'ready',

But I do agree, it is kind of ugly. ;-)

I wonder if it would be easier to do this:
 - use a stored procedure to handle the default value
 - use the table definition to handle the NOT NULL constraint

So you call the stored procedure from ibatis to do the insert, and the
procedure checks for the null value and replaces it.

That would keep the app code clean, the table definition would keep
the data valid, and the stored procedure would manage the default

Also, if you do this outside of the Java code, be sure to re-read the
inserted object in case the database changes it. :)


View raw message