| Author |
entity Boolean field default value
|
Alexander Curvers
Greenhorn
Joined: Apr 03, 2009
Posts: 26
|
|
whats the best way to specify a defailt value for a Boolean entity field,
i would like it to be false but now i get null when i use the getter
even though i set it false in the constructor of the entity it gets set to null when the entity is loaded from database (in the database the value is null by default)
i would like to use annotations so that the table and column are generated in the DB with a default value for the column..
|
 |
Aurelian Tutuianu
Ranch Hand
Joined: May 13, 2004
Posts: 86
|
|
First, JPA does not provide an explicit way to set default values. Use Hibernate annotations for specific defaults.
Still you can do the same thing using @Column and @PrePersist.
- nullable to set column to not allow null values
- columnDefinition - to give a default value (pay attention, this is an sql specific vendor syntax)
If you want to be independent of db, try @PrePersist to set default value like here:
Hope it helped![/img]
|
http://javasign.blogspot.com/
|
 |
 |
|
|
subject: entity Boolean field default value
|
|
|