【发布时间】:2021-02-02 08:54:47
【问题描述】:
CrudRepository#save 不允许您使用默认列。实体的空字段被解释为NULL 而不是DEFAULT。
如果我使用自定义@Query("INSERT INTO ... DEFAULT ..."),那么I'm unable to obtain the ID of the inserted row.
【问题讨论】:
-
你不能在 Bean 本身上设置默认值吗?
-
我认为很多人会喜欢更多的代码。
-
@Jay 这是我对 JenSchauder 说的话:
my reason for not using save is it doesn't seem to support default columns values. Perhaps I could specify the column default in a column definition (like you can with JPA) but this isn't ideal, as now the column definition is duplicated - in the code and in the actual database schema; i.e. if I change the DB schema I must remember to change the code column definition。你的回答是我试图避免的
标签: java postgresql spring-boot spring-data spring-data-jdbc