Support for default values from the DB column definition

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Support for default values from the DB column definition

rwfischer
It appears that the MyBatis generator 1.3.5 does not support default values defined with the DB column.

I am using Java and PostgreSQL, and I have many columns that are defined as "not null default xyz". When I insert a new row using MyBatis and do not specify a value for such a column, I get the following error.
ERROR: null value in column "creation_time" violates not-null constraint

MyBatis should be aware that the column has a default value, and thus should accept the null value.

Is this a bug, or a missing feature? If the latter, could it be added. I should think that the scenario is common enough.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Support for default values from the DB column definition

Jeff Butler
If a column has a default value, then it should not be included in the insert statement if you want to use the default value.  If you are using generated code, you can use the insertSelective method - it will ignore columns with null values.

Jeff Butler


On Wed, Apr 26, 2017 at 6:08 PM rwfischer <[hidden email]> wrote:
It appears that the MyBatis generator 1.3.5 does not support default values defined with the DB column.

I am using Java and PostgreSQL, and I have many columns that are defined as "not null default xyz". When I insert a new row using MyBatis and do not specify a value for such a column, I get the following error.
ERROR: null value in column "creation_time" violates not-null constraint

MyBatis should be aware that the column has a default value, and thus should accept the null value.

Is this a bug, or a missing feature? If the latter, could it be added. I should think that the scenario is common enough.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Support for default values from the DB column definition

rwfischer
Thanks, Jeff. That makes sense.

We are actually migrating from iBatis, and we had customized Abator to handle the defaults (it was a fairly simple change. At the time, iBatis did not have a insertSelective.

Using insertSelective() will require a lot of application code changes, and we were looking at ways to avoid that.

Roger

On Wednesday, April 26, 2017 at 5:23:57 PM UTC-7, Jeff Butler wrote:
If a column has a default value, then it should not be included in the insert statement if you want to use the default value.  If you are using generated code, you can use the insertSelective method - it will ignore columns with null values.

Jeff Butler


On Wed, Apr 26, 2017 at 6:08 PM rwfischer <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="TCCnehcSBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rwfi...@...> wrote:
It appears that the MyBatis generator 1.3.5 does not support default values defined with the DB column.

I am using Java and PostgreSQL, and I have many columns that are defined as "not null default xyz". When I insert a new row using MyBatis and do not specify a value for such a column, I get the following error.
ERROR: null value in column "creation_time" violates not-null constraint

MyBatis should be aware that the column has a default value, and thus should accept the null value.

Is this a bug, or a missing feature? If the latter, could it be added. I should think that the scenario is common enough.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="TCCnehcSBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...