• 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

Problem in matching property type

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks,
I'm new to hibernate.In my code there is a pojo object like


and the corresponding mapping file is



isactive column takes integer datatype in the table department .So is in my hbm file.That means it takes value 0 or 1 to represent boolean output.In my pojo I am putting the isActive property as boolean.
Now I am having problem while writing criteria query.



It gives the exception like
org.hibernate.PropertyAccessException: IllegalArgumentException occurred

If I convert 'isActive' to boolean it is showing class cast exception.
In a nutshell what should I do if the datatype of any property in the pojo class is different from the datatype of the same property in the hbm file (but the property in the hbm file has same datatype with column in the database table).
Is there any solution if I want to solve this problem keeping my pojo class and the database table intact?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could create your own Hibernate type to map 0|1 to false|true and then use this type in your hbm mapping. Basically, Hibernate allows custom type definition, requiring the user to implement org.hibernate.usertype.UserType;. There are a few methods to override but here is an example for what you're after.


Then you just need to map your database column to the newly defined type. For example,

 
reply
    Bookmark Topic Watch Topic
  • New Topic