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; }
Cool
great tip
I believe this is db dependent. Currently the ability to set the default value with annotations (in a non-db-dependent way) is a to-be-implemented feature in Hibernate3.3.0 according to their jira project. See here: http://opensource.atlassian.com/projects/hibernate/browse/ANN-604
Thanks for the tip Mateo – I haven’t used Hibernate since i posted this, and at that time i was only using MySQL… I had no idea it was platform-dependent.
i used this in my mapping
<property name=“accessRole” column=“access_role” generated=“insert” />