2017-07-19 63 views
1

我有一个数据库表与此列:无法存储UUID到MySql数据库使用Hibernate/JPA

uuid CHARACTER(36) NOT NULL 

这也是一个UNIQUE INDEX (uuid),但不是主键。

在实体类,所述UUID列的定义是这样的:

@GeneratedValue(generator = "system-uuid") 
    @GenericGenerator(name = "system-uuid", strategy = "uuid") 
    @Column(name = "uuid", updatable = false, nullable = false) 
    private UUID uuid; 

然后是映入数据库接口的储存库接口:

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

当我打电话saveRepository。保存(),它抱怨uuid值为空:

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement 
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:278) 
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244) 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491) 
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) 
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) 

... ...

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

为了在将记录保存到数据库之前生成uuid,我错过了什么?

感谢提前:)

回答