实体产生的字串ID长度为32

Sol*_*rad 1 java hibernate

我已经预配置了数据库,但无法更改。应用程序的主键是最大长度为32的String。我有一个休眠实体,该实体当前正在使用uuid2策略生成应用程序ID。问题实际上是UUID长度为36,但我需要32。为我生成Application的ID对我来说更好吗?

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

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

    private String name;
}
Run Code Online (Sandbox Code Playgroud)

Sol*_*rad 5

为我的问题找到了解决方案:只是改用策略uuid而不是uuid2

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