-->
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: Query parameter that can be null
PostPosted: Mon May 05, 2008 5:41 am 
Newbie

Joined: Mon May 05, 2008 5:12 am
Posts: 1
Hello


Having a few issues with JPA querying at the moment and i was wondering could anybody help shed some light on it.

Code:

        Query query = em.createQuery(" select user from User user " +
                " where user.id <> :id " +
                " and user.address = :address ");
        query.setParameter("id",user.getId());
        query.setParameter("address",user.getAddress());


basically i want find all users that have the same address as passed in address but excluding my user.
Issue occurs when the parameter address is null. then the query will not return any users in the db that have null address ( confirms to the spec that a null is actually and unknown value). i want to know is there any way to overcome this and create statement that will return users that have null address. i do not want to use
Code:
where user.address is null
because i am not actually looking for address that are null. the only solution that springs to my mind is creating checks on the user before any query is created/called and call a query depending on the value of address. to me this is silly


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.