PDA

View Full Version : Issues with querying on "foreign key" ObjectId



bjornharvold
Jul 15th, 2011, 04:38 PM
Here my java class:



Item.java
@Id
private ObjectId id;
private ObjectId categoryId;


Now I want to query on all items matching a categoryId so I use QueryDsl and query like this:



private final QItem item = new QItem("item");
itemRepository.findAll(item.categoryId.eq(new ObjectId("4e20a1f80364a33a365d82ea")));


The query above always returns null;

In mongo, this should equate to:



db.testdb.item.find({"categoryId" : ObjectId("4e20a1f80364a33a365d82ea")}).

This direct mongo query always returns the correct results.

Ideas? Is there a way to print to my slf4j / log4j log and see exactly what the query that's being created by spring-data-mongodb looks like?

Cheers
bjorn

bjornharvold
Jul 22nd, 2011, 10:06 AM
Update:

Creating a new method on the Repository interface like this:

findByCategoryId(ObjectId catId)

works fine.