-
1. Re: boolean types mapped to bit in MySQL 5 not working with
dustismo Sep 26, 2007 3:41 PM (in response to wquraishi)Column type -
TINYINT(1) UNSIGNED
works for us. -
2. Re: boolean types mapped to bit in MySQL 5 not working with
matt.drees Sep 26, 2007 3:46 PM (in response to wquraishi)As dustismo says, you can represent booleans as tinyint(1) in mysql, which is more readable with browsers, I've found. But you have to specify the columnDefinition attribute of @Column (if you're using hibernate's schema creation coolness), and so you might loose some portability. It'd probably be better to specify it in an orm.xml file.
I haven't done this yet (I'm using the default bits); but I think I will at some point.
If anyone else has found a great way to work with booleans, please chime in. -
3. Re: boolean types mapped to bit in MySQL 5 not working with
dustismo Sep 26, 2007 3:50 PM (in response to wquraishi)I've found that hibernate correctly maps to boolean from tinyint(1) without any other configuration
i.e. this works fine.@Column(name="is_include_trend") public boolean isIncludeTrend() { return this.includeTrend; } public void setIncludeTrend(boolean includeTrend) { this.includeTrend = includeTrend; }
-Dustin -
4. Re: boolean types mapped to bit in MySQL 5 not working with
wquraishi Sep 26, 2007 3:59 PM (in response to wquraishi)This is what I currently have which doesn't work:
@Column(updatable = true, name = "active") public boolean isActive() { return active; } .. setters
So your suggesting that I tell it to create a TinyInt...how would you do that? Thanks. -
5. Re: boolean types mapped to bit in MySQL 5 not working with
wquraishi Sep 26, 2007 4:03 PM (in response to wquraishi)Actually nix my last comment asking about how to do it. Don't know where my mind is.... It would be something like
@Column (...., columnDefinition = "TINYINT")
right? -
6. Re: boolean types mapped to bit in MySQL 5 not working with
wquraishi Sep 26, 2007 4:07 PM (in response to wquraishi)You guys rock! That fixed it. Thanks for the quick resolution.
-
7. Re: boolean types mapped to bit in MySQL 5 not working with
matt.drees Sep 26, 2007 4:07 PM (in response to wquraishi)"dustismo" wrote:
I've found that hibernate correctly maps to boolean from tinyint(1) without any other configuration
Do you mean for normal usage, or also for schema creation?
IIRC, it maps to tinyints fine (w/ no additional configuration) if you have a pre-existing table, but if hibernate has to make a table, it'll by default choose bit. -
8. Re: boolean types mapped to bit in MySQL 5 not working with
dustismo Sep 26, 2007 4:19 PM (in response to wquraishi)
Do you mean for normal usage, or also for schema creation?
IIRC, it maps to tinyints fine (w/ no additional configuration) if you have a pre-existing table, but if hibernate has to make a table, it'll by default choose bit.
Sorry, I should have mentioned that we always do our database modeling first, then create the hibernate models. That is, I've never had hibernate generate a table so I'm not sure how it would handle booleans.
-Dustin