-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Using Boolean with MySQL
PostPosted: Tue Jul 20, 2004 1:02 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
Hi,

I am using Hibernate 2.1.12 with MySQL 4.0.20d. In the past I have used SAPDB and it has been easy enough to use Boolean. But due to the lack of a Boolean type in MySQL, I was wondering if going with Bit as the MySQL data type and java.lang.Boolean as the mapping type would cause any problems. I am NOT using Middlegen. I would prefer not to use primitives in my POJOs. Any suggestions are greatly appreciated.

If this topic has been discussed at great lengths in the past, please point me to the right discussion. I have been trying to find a discussion but have drawn a blank so far. Same for Google.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 3:03 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 3:44 pm
Posts: 43
I am successfully using this tag with MySQL 4.0.15:
Code:
<property name="locked" type="boolean"/>

Schemaupdate maps that to a tinyint with a length of 1. It sticks a "1" in the DB for true values. I don't have any false values right now, but I'd guess you'd get a "0".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 3:10 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
scrotch wrote:
I am successfully using this tag with MySQL 4.0.15:
Code:
<property name="locked" type="boolean"/>

Schemaupdate maps that to a tinyint with a length of 1. It sticks a "1" in the DB for true values. I don't have any false values right now, but I'd guess you'd get a "0".


Actually I saw a post from someone else in the forum who said that he is only getting 0s for tinyint, which is another reason I was unsure. Have you tried doing
<property name="locked" type="java.lang.Boolean"/>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 3:12 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 3:44 pm
Posts: 43
I have not had cause to try a Boolean, just the primitive. Sorry.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 3:20 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
scrotch wrote:
I have not had cause to try a Boolean, just the primitive. Sorry.
[/quote]

I just read the Appendix for "Hibernate: A Developer's Notebook" on Safari and it says the following.


    Type class Boolean
    Type name boolean
    SQL type BIT
    Notes A basic type



So I guess I am going to have to try out BIT with java.lang.Boolean and see what it does. If anyone has already tried it, please let me know. Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 2:07 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
gpani wrote:
So I guess I am going to have to try out BIT with java.lang.Boolean and see what it does. If anyone has already tried it, please let me know. Thanks in advance.


Well, I tried using BIT as the data type and java.lang.Boolean as the type in the Hibernate mapping and even when I implicitly passed in new Boolean(true) into the object to saveOrUpdate() it stored a 0 to the Bit. Any ideas how I could solve this problem? Do I have to use a TINYINT instead of a BIT. If so, do I need to make the TINYINT(1) or will using the 8-bit signed value still work for java.lang.Boolean?

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 3:09 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
Sorry all for this mess. I was using an antiquated MySQL Driver that came with my Resin distro. I just got the latest driver from the mysql site and it works fine now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.