使用jpa可以生成uuid,但是我直接添加数据没有id值会报错,只在程序中有效,如果直接修改数据库需要手动填写,另外长度不要乱填 ,之前填了200,找了半天才找到原因。

package com.java1234.entity;

import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
@Entity
@Table(name = "ip_user")
@Data
/**
 * uuid关键
         */
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")   

public class User2 {
    /**
     * uuid关键
     */
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    private String id;



    @NotEmpty(message="请输入用户名!")
    @Column(length=50)
    private String userName; // 用户名

    @NotEmpty(message="请输入密码!")
    @Column(length=50)
    private String password; // 密码
}

 

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2021-09-30
  • 2022-01-04
  • 2021-06-10
  • 2021-11-01
  • 2022-01-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
相关资源
相似解决方案