What is value field of @ColumnDefault in jpa?
I am not native.
I needed to use default value in jpa.I referenced this and then I used @ColumnDefault. It works good.But I want to know role of value field of @ColumnDefault. comment of value of @ColumnDefault
The DEFAULT definition to apply to the DDL.
But I don't know what means DEFAULT definition? Even if I use @ColumnDefault("5000"), It is not applied 5000 only is applied default value 1000 of DDL.
What is role of value field of @ColumnDefault?
Thank you.
Solution 1:
DEFAULT
definition just mean the SQL default value for a column which can be defined by following DDL:
CREATE TABLE Person (
name VARCHAR(255) DEFAULT 'N/A'
)
The value 'N/A' is the default definition for the column name , which is equivalent to the following mapping :
@Entity(name = "Person")
public class Person {
@Column("name")
@ColumnDefault("'N/A'")
private String name;
}
@ColumnDefault
is only useful when you use hibernate.hbm2ddl.auto
to let hibernate to auto create/update your DB schema. If you do not use such auto-schema generation feature, it will not have any effect.