如何使用Hibernate JPA 2以二进制形式存储uuid

pie*_*tou 5 java binary uuid hibernate jpa-2.0

我有一个关于通过休眠持久性(JPA2)以二进制形式在数据库中的字符串uuid的问题。我现在正在使用此代码:

private UUID id;

@Id
@Type(type="uuid-char")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(length = 32, unique = true, nullable = false)
public final UUID getId() {
    return id;
}
Run Code Online (Sandbox Code Playgroud)

这项工作正常,但我必须以二进制形式存储它。不要问我为什么,但是我必须。

Adr*_*Cox 7

二进制UUID的类型为uuid-binary。您必须具有Hibernate 3.6才能起作用。

有关更多详细信息和陷阱,请参阅此问题的答案。