Here is my JPA2 / Hibernate definition:
Code:
@Column(nullable = false)
private boolean enabled;
In MySql this column is resolved to a bit(1) datatype - which does not work for me. For legacy issues I need to map the boolean to a tinyint not to a bit. But I do not see a possibility to change the default datatype. Is there any?
解决方案
Try the NumericBooleanType. For some reason this doesn't have a declared short type name so you'd have to use:
@Column(nullable = false)
@Type(type = "org.hibernate.type.NumericBooleanType")
private boolean enabled;
This does map to an INTEGER type but it will probably work fine with a TINYINT.
UPDATE: org.hibernate.type.NumericBooleanType Does not work with TINYINT in some RDBMS. Switch the database column type to INTEGER. Or use a different Java @Type value, or columnDefinition, as appropriate.
In this example, Dude's answer of @Column(nullable = false, columnDefinition = "TINYINT(1)") would work without any database changes.