【发布时间】:2021-01-10 20:20:19
【问题描述】:
我的 Spring Boot 应用程序中有以下实体,它由 SQL Server 数据库支持。
@Entity
@Table(name="people")
public class Person {
@Id
@GeneratedValue(strategy=TABLE)
private Long id;
@Column(
columnDefinition="datetime default current_timestamp",
nullable=false, updatable=false, insertable = false
)
private String strTimestamp;
// ...
}
使用 JpaRepository 调用 save 并生成 id 但 strTimestamp 为空,即使我立即调用 getOne 或调用(本机查询)select * from people where id = ?,使用新返回的 Id,该列仍然为空。
有趣的是,如果我对先前插入的行的 id 进行硬编码,它会返回该记录。
我想在插入后返回整行,因为我需要生成的列。
我怎样才能做到这一点?
谢谢。
【问题讨论】:
标签: sql-server spring-boot hibernate spring-data-jpa