tags:

views:

47

answers:

1

As per docs org.hibernate.type.YesNoType is supposed to generate char(1) during schema2ddl generation. But the following definition generates char(255) by default for databases like H2, MySQL

@Column(name = "enabled")
@Type(type = "org.hibernate.type.YesNoType")
private Boolean enabled = Boolean.FALSE;

Adding a hardcoded value for columnDefinition as "char(1)" does create the SQL properly. What am I missing here, is there any workaround to solve this issue without using columnDefinition?

+1  A: 

@Column annotation defaults length to 255; hence the behavior you're seeing.

Removing it won't help either, actually, because implicit column definition created by Hibernate's AnnotationBinder iin the absence of explicit @Column / @Columns also defaults to 255 :-)

You need to explicitly specify column length but the good news is you don't have to do that via columnDefinition:

@Column(name = "enabled", length = 1)
ChssPly76
thanks very much, the issue is resolved now
Joshua