-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: EnhancedUserType to represent null as false
PostPosted: Wed Sep 01, 2010 4:22 am 
Newbie

Joined: Wed Sep 01, 2010 3:55 am
Posts: 3
Hello

I have multiple entity (I don't own the tables) that have properties that represent a Boolean value as either '1' (true) or null (false) in the database (Oracle 10g).
I wrote an EnhancedUserType which works great for the most part.

The only problem I am experiencing is when I want to do a HQL query for false values.

Example:
Code:
    from MyEntity where propertyWithMyType = false

It works when searching for true values but when searching for false I don't know what to put in the objectToSQLString method.
Returning an empty string or null doesn't work.

Code:
    public String objectToSQLString(Object value) {
                return ((Boolean) value ) ? "'1'" : "?????"; // I don't know what to put here for the false value
    }

I checked the SQL that gets created and it seems the value returned from objectToSQLString() is placed on the right-hand side of an equals sign (=) in the query. This doesn't seem to work for null values (If I manually run the query on the database but replace the '=' with 'is' it works).

I am using Hibernate 3.5.1-Final.

Any ideas what I can do to let the queries work correctly for false(null in the database) values?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.