gpt4 book ai didi

@CreationTimestamp with value from DB is excessive?(@CreationTimestamp的值来自数据库是否过大?)

转载 作者:bug小助手 更新时间:2023-10-28 10:41:03 29 4
gpt4 key购买 nike



Is there any reason to add annotation

有没有理由添加注解


@CreationTimestamp(source = SourceType.DB)

instead of

而不是


@Column(updatable = false, insertable = false)

except for db schema-generation?
Anyway value will be set by DB.

除了数据库架构生成之外?无论如何,值将由DB设置。


Moreover, CreationTimestamp is not compartible with Immutable, and cause error JpaSystemException: Lock mode not supported

此外,CreationTimestamp与不可变不可分,并导致错误JpaSystemException:不支持锁定模式


更多回答
优秀答案推荐

There are a bit differences in term of the generated insert SQL and the configuration of the create timestamp column.

在生成的INSERT SQL和CREATE TIMESTAMP列的配置方面有一些不同。


@Column(updatable = false, insertable = false) requires you to configure the DB column to have a default value which is set to the current timestamp. The generate SQL will not include the created time column because of insertable=false

@COLUMN(UPDATABLE=FALSE,INSERTABLE=FALSE)要求您将DB列配置为具有设置为当前时间戳的默认值。由于INSERTABLE=FALSE,生成的SQL将不包括创建的时间列


@CreationTimestamp(source = SourceType.DB) does not require the DB column to have such default value setting. Hibernate will call the current timestamp fucntion from DB, and use its value to generate the insert SQL.

@CreationTimestamp(source = SourceType.DB)不要求DB列具有此类默认值设置。Hibernate将从DB中调用当前时间戳函数,并使用其值生成插入SQL。


更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com