gpt4 book ai didi

java - 实体生成的字符串 id 长度为 32

转载 作者:行者123 更新时间:2023-11-29 06:30:04 24 4
gpt4 key购买 nike

我有预配置的数据库,我无法更改。应用程序的主键是最大长度为 32 的字符串。我有 hibernate 实体,目前正在使用 uuid2 策略生成应用程序 ID。问题实际上是,UUID 长度是 36,但我需要 32。如何为应用程序生成 ID 对我来说更好?

Bellow 是我当前实体的简化版本。

@Entity
public class Application {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String applicationId;

private String name;
}

最佳答案

为我的问题找到了解决方案:刚切换到策略 uuid 而不是 uuid2

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "application_id")
@Size(max = 32)
private String applicationId;

关于java - 实体生成的字符串 id 长度为 32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37622124/

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