插入NULL而不是默认列值

时间:2016-05-05 06:25:14

标签: mysql hibernate

我的MySQL数据库中有一个表,其中包含一个默认值的列status,使用phpMyAdmin在数据库端定义。当我使用Hibernate插入一个新行时,我收到此错误:

  

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:   列'status'不能为null

我是否还需要做更多的事情才能使用默认值?

实体

@Entity
class Purchase {

    //More fields
    private String status;

    @Basic
    public String getStatus() {
        return status;
    }

}

1 个答案:

答案 0 :(得分:3)

使用字段的默认值

document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady()
{
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;
}
function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

function onPhotoURISuccess(imageurl){
       imagesize(imageuri)
      largeImage.src = imageURI;
}

var imagesize = function(imagedata){

window.resolveLocalFileSystemURI(imagedata,function(fileEntry){
**fileEntry.file(function(fileObj)**{


});

});
};

或使用@PrePersist Annotion,

private String status = "Default";