I know there are plenty of these questions here on SO and also on the net, but all the answers suggest using columnDefinition which is database specific and hen
I don't think you need any documentation, the java docs are self explaining. If I understand you correctly you need a way to set a default value for a field. If yes please see the following code snippet.
@Entity
@Table(name = "my_entity")
public class SomeEntity extends BaseEntity {
public static final class MyValueGenerator implements
ValueGenerator<String> {
@Override
public String generateValue(Session session, Object owner) {
return "This is my default name";
}
}
@Basic
@Column(name = "name", insertable = true, updatable = true, nullable = false, length = 255)
// This will add a DDL default
@ColumnDefault("'This is my default name'")
// This will add a runtime default.
@GeneratorType(type = MyValueGenerator.class)
private String name;
// getters and setters
}
Following is working for me.
@ColumnDefault("'0.0'")
@Column(name = "avgRating")
private float avgRating;