aspose file tools*
The moose likes Object Relational Mapping and the fly likes [Hibernate] Boolean mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Hibernate] Boolean mapping" Watch "[Hibernate] Boolean mapping" New topic
Author

[Hibernate] Boolean mapping

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Hi there, I'm using JBoss 4.0.5 GA and I'm trying to map a POJO class into MySQL 5 Everything works fine except for the Boolean field which is empty. I tried different attempts but I'm probably missing something about.
Would you have a look on my code and tell me why I'm getting that result?


Once I persist the class I print out the toString() in order to verify the properties object, actually the active prop. has the right false value. So why on the DB I get an empty value?
[ March 25, 2007: Message edited by: Alessandro Ilardo ]

trying to decode a woman mind....
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Why not use primitive boolean in this case?


Object type Boolean will be used when the usecase permits the property value to be null. Having said that, i am not sure why you are seeing the value as false when you do a toString(). I would have expected it to be null.


[My Blog] [JavaRanch Journal]
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
thanks for your reply.
Actually it was a native boolean, but I read somewhere that with Hibernate was better use Boolean instead (don't ask me why).

The value false, is correct, it's set by the constructor.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Originally posted by Alessandro Ilardo:
(don't ask me why).



No, i wont

Sometime back i had read an article which mentioned that MySQL doesnt fully support Boolean. They had recommended using TINYINT(1) as the data type in the ddl while creating the table. I am not completely sure if this the reason why you are seeing this issue, but you could give it a try by changing the data type to TINYINT(1) in your table.
aga javed
Greenhorn

Joined: May 28, 2008
Posts: 1
I m facing a problem regarding boolean type mapping with mysql datatype while auto ddl'ing. The column type corresponding to boolean created by hibernate is BIT(1) instead of mysql boolean type (Tinyint or boolean).

Can anybody solve this problem.
Thanks in advance
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Aga,

Welcome to JavaRanch

Which version of MySql do you have in your application? Are you using the correct JDBC driver version? And what dialect have you specified in your hibernate configuration file? Can you post the hbm.xml which contains this boolean mapping?
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Hibernate needs Boolean instead of boolean, when you have null-Columns.

boolean cannot be null, the Wrapper Boolean can be null.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: [Hibernate] Boolean mapping