Hibernate ID为VARCHAR类型时主键生成策略

阅读更多
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;

@MappedSuperclass
public abstract class AbstractEntity implements Entity {
  

    private static final long serialVersionUID = -1L;
    @Id
    @GenericGenerator(name = "systemUUID", strategy = "uuid")
    @GeneratedValue(generator = "systemUUID")
    @Column(name = "id", insertable = true, updatable = true, nullable = false)
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

 通过注解,可以通过hibernate实现实体类的VARCHAR类型主键自动生成UUID。

你可能感兴趣的:(java,hibernate,主键生成策略)