"IS NULL" not working as expected in Kundera(3.0)-MongoDB

28 views
Skip to first unread message

Balaji Balakrishnan

unread,
Aug 27, 2015, 1:23:22 PM8/27/15
to kundera-discuss
Hi,
I just started with Kundera(3.0)-MongoDB. I had written a  simple query "Select m from AssetCategory m  where m.parentId is NULL"
I was expecting categories whose parent id is null or parent id is missing but I am getting all the records from "AssetCategory including the records whose parentId is not null.

> db.Asset_Category.find()
{ "_id" : "4592cf6a-1145-440d-b231-152815842c53", "NAME" : "TV" }
{ "_id" : "2d1efce9-0e11-4738-9c53-e4e99801896c", "NAME" : "LED", "PARENT_ID" : "4592cf6a-1145-440d-b231-152815842c53" }
{ "_id" : "1ff952d6-7d94-49c1-808e-3aedde6d560f", "NAME" : "Washing Machine" }

what I was expecting is 

> db.Asset_Category.find( { PARENT_ID : null} )
{ "_id" : "4592cf6a-1145-440d-b231-152815842c53", "NAME" : "TV" }
{ "_id" : "1ff952d6-7d94-49c1-808e-3aedde6d560f", "NAME" : "Washing Machine" }

I modified the query to "Select m from AssetCategory m  where m.parentId = :pid" and passed null for "pid" but I get NPE. shouldn't this converted to "PARENT_ID : null".



Balaji Balakrishnan

unread,
Aug 27, 2015, 2:34:00 PM8/27/15
to kundera-discuss
For query = "Select m from AssetCategory m  where m.parentId IS NULL", the where clause sent by Kundera is {} and that's why all records are returned.
For query = "Select m from AssetCategory m  where m.parentId = null", the where clause sent by Kundera is {"PARENT_ID" : "null"} but still it's not working.I guess this expects the field with null value. 
For now, em.createNativeQuery("{\"PARENT_ID\": { $exists: false } }",AssetCategory.class) works but of course this is specific to Mongo.

Amit

unread,
Aug 28, 2015, 8:38:06 AM8/28/15
to kundera-discuss
@Balaji

Marking it as an issue , we will try to fix it ASAP.
Could you please raise it at github (https://github.com/impetus-opensource/Kundera) ?

-Amit
Reply all
Reply to author
Forward
0 new messages