I want to set default values if not specified by user. eg, for Boolean private isValid , if we don't specify any json value, then it should set false . I am using hibernate validator, @NotNull, @NotBlank, @Size, @Range...Is there any annotations to set default value for boolean, int, float, irrespective of data types. I tired hard, but did not come up with any solution. Still I am trying..Your help is highly appreciated ! Thank you
2 Answers
Just add default value with column
@Column(name="isValid",columnDefinition="tinyint(1) default '0'")
private Boolean isValid;
4 Comments
sayan
I get compilation error "create annotation Column", could you please mention the required jar. I am not using Hibernate ORM.
Harshal Patil
@sayan Get jar here mvnrepository.com/artifact/org.hibernate.javax.persistence/…
sayan
I tried, but it didnt work. I am not using Hibernate ORM for my code, that's why it didnt work, I guess. I am only using hibernate-validator jars for validation purpose, not hibernate orm. Is there anything to set default values using annotations ? Please help. thnx.
Harshal Patil
@sayan This is the only way to set default value using java JPA annotations. check edited answer and try again.
booleaninstead ofBoolean...