Announcement Announcement Module
Collapse
No announcement yet.
Issues with querying on "foreign key" ObjectId Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues with querying on "foreign key" ObjectId

    Here my java class:

    Code:
    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:

    Code:
    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:

    Code:
    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
    Last edited by bjornharvold; Jul 15th, 2011, 05:41 PM.

  • #2
    Update:

    Creating a new method on the Repository interface like this:
    Code:
    findByCategoryId(ObjectId catId)
    works fine.

    Comment

    Working...
    X