Default value not working in hibernate

后端 未结 4 1830
囚心锁ツ
囚心锁ツ 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:11

    Your proposed solution should work, but is database dependent, so you might want to check up on whether your syntax actually works with your concrete DB. Another more generic approach is

    @PrePersist
    void preInsert() {
       if ( getSourceFrom() == null ) { setSourceFrom( "Case" ); }
    }
    

    Cheers,

提交回复
热议问题