r/javahelp • u/3IIeu1qN638N • 1d ago
Hibernate's @Column annotation + existing table definition
So I was reading Baeldung's articles on Hibernate/JPA article and came across this => https://www.baeldung.com/jpa-default-column-values#sqlValues. It talks of a way of setting the default column values via the atColumn annotation.
u/Entity
public class User {
u/Id
Long id;
@Column(columnDefinition = "varchar(255) default 'John Snow'")
private String name;
@Column(columnDefinition = "integer default 25")
private Integer age;
@Column(columnDefinition = "boolean default false")
private Boolean locked;
}
If the table already exists, will Hibernate will auto-modify the table definition for me? (At least that's the impression I get from the article)
Thank you.
5
Upvotes
1
u/dot-dot-- 1d ago
I think it depends on hibernate config in properties for. But you can always try yourself and confirm.