Java – Setting default values for columns in JPA


Is it possible to set a default value for columns in JPA, and if, how is it done using annotations?

Best Solution

You can do the following:

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.