Reputation: 87167
How do I map a CHAR(1) to a boolean using Hibernate for Java?
Upvotes: 8
Views: 10783
Reputation: 925
For me the following did the thing:
@Type(type = "org.hibernate.type.NumericBooleanType")
@Column(name = "STATUS", columnDefinition = "CHAR(1)", length = 1)
private Boolean status;
Column definition:
STATUS NOT NULL CHAR(1)
Technologies:
Upvotes: 0
Reputation: 43
You can map like this:
@Type(type = "org.hibernate.type.TrueFalseType")
@Column(name = "IsValid", columnDefinition = "CHAR(1)", length = 1)
private Boolean valid;
Upvotes: 0
Reputation: 10665
CharBooleanType is probably what you are looking for http://www.hibernate.org/hib_docs/v3/api/org/hibernate/type/class-use/CharBooleanType.html
edit: dtsazza's answer is probably more useful if you just want to get going and use characters y/n or t/f. If those don't match your usage you can implement your own type using CharBooleanType.
Upvotes: 2