File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Problem in matching property type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem in matching property type" Watch "Problem in matching property type" New topic

Problem in matching property type

Saptarshi Chakraborty

Joined: Jul 26, 2007
Posts: 23
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?
Brett Maclean

Joined: May 01, 2009
Posts: 22
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,
Follow us on Twitter:
I agree. Here's the link:
subject: Problem in matching property type
It's not a secret anymore!