引导spring-hibernate+jpa不返回数据库级生成的列



我的spring启动应用程序中有以下实体,它由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为null,即使我立即调用getOne或调用(本机查询(select * from people where id = ?,使用新返回的id,该列仍然为null。

有趣的是,如果我硬编码之前插入的行的id,它会返回该记录。

我想在插入后返回整行,因为我需要生成的列。

我怎样才能做到这一点?

谢谢。

将strTimestamp数据类型更改为java.util.Date并尝试。同时使用@Temporal注释

@Temporal(TemporalType.TIMESTAMP)
@Column( columnDefinition="datetime default current_timestamp", nullable=false, updatable=false, insertable = false ) private String strTimestamp;

最新更新