jpa生成uuid


使用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; // 密碼
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM