无法使用hibernate/jpa将UUID存储到MySql数据库中

无法使用hibernate/jpa将UUID存储到MySql数据库中,hibernate,jpa,spring-data,uuid,Hibernate,Jpa,Spring Data,Uuid,我有一个包含此列的db表: uuid CHARACTER(36) NOT NULL 它也是一个唯一索引(uuid),但不是主键 在实体类中,uuid列的定义如下: @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Column(name = "uuid", updatable = false, nullable =

我有一个包含此列的db表:

uuid CHARACTER(36) NOT NULL
它也是一个
唯一索引(uuid)
,但不是主键

在实体类中,uuid列的定义如下:

    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "uuid", updatable = false, nullable = false)
    private UUID uuid;
然后是一个存储库接口,它是spring数据存储库接口:

@Repository
public interface SaveRepository extends Repository<CoreEvent, Integer> {
}

Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'uuid' cannot be null
在将记录保存到数据库之前,我是否错过了生成uuid的任何操作


提前感谢:)

u可以使用@PrePersist之类的事件来填充UUID字段

但是为什么不在创建对象时分配uuid呢uuid=uuid.randomUUID()?

复制品?

:)
Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'uuid' cannot be null