While database design I used a field name deleted and use it as Boolean. Everything seems fine.
I’m using hibernate 3.6.9. So I’ve configured applicationContext
prop key=”hibernate.query.substitutions”>true=1 false=0
In my sessionFactory bean. So when Im saving my object, it converting my Boolean as 1/0.
So but problem is when Im retrieving object from database, Im getting
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Boolean
Can any of you tell how to solve this problem?
I would guess that
hibernate.query.substitutionsonly work for queries, but not for entities.What I would try is to implement a Custom User Type that maps a boolean to 1 or 0. And than use that custom user type to annotate the boolean field of my entity.
Have a look at this blog for an example how to implement a custom type. (I am not 100% sure, but I remember that there was somehow two concepts of custom types in hibernate, one more powerful than the other)
But definitely have a look at the standard custom type “yes_no”, that is really close to the one you need to write.