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