我有一个应用程序,其中我有PK Id的自动递增。我必须添加其他自动递增的列,并且我使用liquibase来使其工作-- liquibase为自动递增创建了序列。当我从查询工具进行插入时,或者当我没有在实体中映射此字段并使持久化自动递增工作时。但当我补充说:
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "next_value", nullable=false, unique=true)
private Long nextValue;我得到了一个丑陋的错误:
Caused by: org.postgresql.util.PSQLException: ERROR: empty value in the "next_value" column violates the limit of the required value“这里出了什么问题?
编辑:
我的liquibase更改集添加此列并使其自动递增:
<addColumn tableName="table">
<column name="next_value" type="number"/>
</addColumn>
<addAutoIncrement
columnDataType="number"
columnName="next_value"
incrementBy="1"
startWith="1"
tableName="table"/>
<sql>select setval('table_next_value_seq', (select cast(current_value+1 as bigint) from gapless_sequence), false)</sql>setval用于启动它,而不是从%1开始
发布于 2018-12-14 17:57:01
您必须禁用insertable和updatable false
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "next_value", unique = true, nullable = false, insertable = false,updatable = false)发布于 2018-12-14 17:41:30
我猜它应该在db中更改表。
ALTER TABLE tblName(
nextValue LONG NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),……
https://stackoverflow.com/questions/53776829
复制相似问题