hibernate主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.(代
Posted Angel挤一挤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hibernate主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.(代相关的知识,希望对你有一定的参考价值。
主键生成策略使用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。
实体如下:
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; } }
有这个警告之后,处理如下:
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; } }
即可解决这个警告。
以上是关于hibernate主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.(代的主要内容,如果未能解决你的问题,请参考以下文章