Default value not working in hibernate

后端 未结 4 1827
囚心锁ツ
囚心锁ツ 2021-02-10 01:05

I have use columnDefinition to specify default value for a column, however it does not store default value it stores null only,

Please help regarding this,

4条回答
  •  既然无缘
    2021-02-10 01:29

    Your default value is defined in database, so Hibernate doesn't use it. The default value is set by database, but the entity you created is already in hibernate cache (it can be session cache or L2 cache).

    If you load the entity it comes from Hibernate cache rather from database.

    To solve this problem invoke do one of:

    • refresh the entity session.refresh(yourEntity)
    • initialize it using java instead of via default value
    • use @PrePersist listener

提交回复
热议问题