There is no annotation to specify default value for a column
Description
relates to
Activity
Matt Hauck July 8, 2014 at 7:54 PM
I propose this issue should get re-opened. I think HHH-2907 looks far too complicated a thing to use to implement a simple default value on a newly added non-null column. This is such a common thing to do, I see no reason why hibernate annotations should not support it. I don't believe this problem is too difficult to solve, since this is already supported by the xml. There is already code somewhere generating the default column value ddl! In my opinion this is simply a gap between the xml and the annotations. This also makes it seem fairly easy an issue to fix. The column definition is not a valid workaround either, I think, because it replaces what hibernate ddl generation is supposed to be doing for me, and it is not database-independent.
It is really hard to believe that this gap has been known for 7 years, is considered "minor", and was recently closed as WONTFIX!
Please reconsider.

Brett Meyer October 16, 2013 at 9:31 PM
Closing this – HHH-2907 will provide this capability.
Steve Ebersole October 3, 2013 at 12:27 PM
This relates also to the notion of "generated values". Its more than just defining the DEFAULT value on the db side...

tscho July 28, 2010 at 1:36 PM
A possible workaround is to use the columnDefinition parameter in the @Column annotation. For example: @Column(name="myInt", columnDefinition="INTEGER DEFAULT 17"). Though this solution is database specific it worked fine for me so far.
But there is a major problem with this solution when it comes to primary keys (PK is a random UUID in a PostgreSQL 8.4 database):
class PkEntity {
@Id @Column(nullable = false, unique = true, updatable = false, columnDefinition = "uuid DEFAULT uuid_generate_v4()")
java.util.UUID id;
}
When this entity is referenced from another entity like this (nullable FK):
class FkEntity {
@ManyToOne(optinal=true)
@JoinColumn
PkEntity pkEntity;
}
the generated schema looks like this:
CREATE TABLE fk_entity (
pk_entity uuid DEFAULT uuid_generate_v4()
)
and this is of course not what I want my nullable FK to look like!
Arik Kfir June 20, 2010 at 9:04 PM
Hi,
Are there any plans to implement this in a coming release? While I don't agree this is a blocker, it will definitly make things much easier for teams working on the same project and schema.
Details
Details
Assignee

Reporter

In hibernate annotation you can't specify default value for a column.
If you use xml files for mapping then you have this feature.
I consider that this is a major problem with annotation.