【hibernate】主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values;
主键生成策略使用UUID报出如警告如下:
控制台- 2017-11-24 18:40:14 [restartedMain] WARN org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead
说是它不生成符合IETF RFC 4122标准的UUID值; 请考虑使用org.hibernate.id.UUIDGenerator。
实体如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.sxd.entity; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @Entity @GenericGenerator(name = "jpa-uuid", strategy = "uuid") public class User { private String id; private String username; private String password; private Integer age; @Id @GeneratedValue(generator = "jpa-uuid") public String getId() { return id; } public void setId(String id) { this.id = id; } @Column(nullable = false) public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Column(nullable = false) public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Column(nullable = false) public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public User() { } public User(String id, String username, String password, Integer age) { this.id = id; this.username = username; this.password = password; this.age = age; } }
有这个警告之后,处理如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.sxd.entity; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @Entity @GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator" ) public class User { private String id; private String username; private String password; private Integer age; @Id @GeneratedValue(generator = "uuid2") public String getId() { return id; } public void setId(String id) { this.id = id; } @Column(nullable = false) public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Column(nullable = false) public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Column(nullable = false) public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public User() { } public User(String id, String username, String password, Integer age) { this.id = id; this.username = username; this.password = password; this.age = age; } }
即可解决这个警告。