Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Hibernate] Boolean mapping

 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate needs Boolean instead of boolean, when you have null-Columns.

boolean cannot be null, the Wrapper Boolean can be null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic