我有一个关于通过hibernate持久化(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;
}
这很好,但我必须以二进制形式存储它。不要问我为什么,但我一定要。
二进制UUID的类型为uuid-binary
。你必须有Hibernate 3.6才能工作。
有关更多细节和陷阱,请参阅此问题的答案。