Setting default values for columns in JPA

You can do the following:

@Column(name="price")
private double price = 0.0;

There! You’ve just used zero as the default value.

Note this will serve you if you’re only accessing the database from this application. If other applications also use the database, then you should make this check from the database using Cameron’s columnDefinition annotation attribute, or some other way.

Leave a Comment