Why does Spring's JDBC Templates doesn't use the tables default value
You need to limit the columns specified in the SQL Insert.
See SimpleJdbcInsert.usingColumns()
If you don't do this, the SQL statement will need values for ALL columns and the default values cannot be used.
e.g. use
insert into mytable (col1, col2) values (val1, val2);
instead of
insert into mytable values (val1, val2);
The problem is somewhere else: when I use SimpleJdbcInsert
and pass a map of parameters to it, I simple expect to create insert statment only with parameters I provided. I have a NOT NULL column in the table with DEFAULT value and I don't want to specify it. I also don't want to explicitly put all column names in usingColumns()
as I've just do it when creating a map of parameters! Why should I do it again? The problem is that SimpleJdbcInsert
want's to be smarter and add all columns to insert statement which is not necessary. Why not create a statement only using columns provided with parameters map?
See: http://forum.spring.io/forum/spring-projects/data/54209-simplejdbcinsert-and-columns-with-default-values