Default Values With Hibernate Annotations

To set the default value of a field with Hibernate, you can use the columnDefinition argument :

/**
 * Returns the file size of this Photo
 */
@Column(name="file_size",nullable=false,columnDefinition="bigint(20) default 0")
public Long getFileSize() {
    return fileSize;
}
    
/**
 * Sets the file size of this Photo
 *
 * @param fileSize File size of this Photo
 */
public void setFileSize(Long fileSize) {
    this.fileSize = fileSize;
}



One Response to “Default Values With Hibernate Annotations”  

  1. 1 Okada

    Cool

    great tip

Leave a Reply