wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem in matching property type" Watch "Problem in matching property type" New topic
Author

Problem in matching property type

Saptarshi Chakraborty
Greenhorn

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
Greenhorn

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,


http://www.ontruenorth.com
Follow us on Twitter: http://twitter.com/truenorth_buzz
 
Consider Paul's rocket mass heater.
 
subject: Problem in matching property type
 
Similar Threads
Doubt in Mapping Associations
Mapping Error Hibernate
Parent-Child Confusion ....
Many to Many mapping in hibernate.
hbm without primary key