Hibernate columnDefault true needs to be mapped to sqlserver BIT default 1

89 views Asked by At

I have a need to map the @org.hibernate.annotations.ColumnDefault("true") to BIT default 1 in generated SQL schema. Is there anyway other than adding a @Column(columnDefinintion="BIT default 1")

I'm using SQL Server 2008 Dialect and hibernate 5.3.26 and XPAND for code generation.

I have tried using @org.hibernate.type.BooleanType also but it did not work. Done some debugging in hibernate core also and in org/hibernate/cfg/Ejb3Column.java:625 where it takes the @ColumnDefault annotation value and later set it as it is without mapping in org/hibernate/mapping/Table.java:561. May be I have missed something. Is there anyway to override this functionality?

Where is the SQL type and default value mapping happens in schema generation? classes methods etc.

Any help would be grateful.

1

There are 1 answers

0
Lahiru Pathirana On BEST ANSWER

Using the below combination resolved the issue.

@org.hibernate.annotations.Type(type = "org.hibernate.type.BooleanType")
@org.hibernate.annotations.ColumnDefault(value = "1")