• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data conversion in Hibernate

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a column in database of type smallint.It is guranteed that the column will have values 0 and 1.In Hibernate I have mapped this as
.

I want to convert this column to a boolean value in my POJO.0 = false, 1 = true. Can I do that ?

Right now, this mapping is giving error because there is a NULL value in one of the records , inspite of having .How can I avoid this ?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try type="yes_no" in your property mapping in hbm.xml and use a boolean datatype for the property in your pojo instead of Boolean. "yes-no" type converts 0 to false and 1 to true boolean datatype. And not-null="true" only tells that at the time of insertion/updation of a record through hibernate, null value is not acceptable. In your particular case, you could think of updating your database if its not a prod database and/or giving a default value for this column in the database table so that you would not encounter a null value.
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Lakshmi, it works great.
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help !! This is not working while updating. I am setting a boolean value to the field and it's giving "Implicit conversion from datatype 'CHAR' to 'INT' is not allowed.Use the CONVERT function to run this query.". I am using Sybase DB.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, before I was going to suggest creating a UserType like the on eposted here at Hibernate's website

http://www.hibernate.org/189.html

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic