Skip to content

QueryMapper and UpdateMapper do not properly consider @DocumentReference to non-id properties #3853

Closed
@mp911de

Description

@mp911de

Using document references with non-Id properties in the context of queries and updates render invalid query documents. Consider the two examples below.

@DocumentReference(lookup = "{ 'name' : ?#{#target} }")
Query: {"customer": {"target": "wu"}, "sample": {"$oid": "615c04ae3fc147443f2a3352"}}

@DocumentReference(lookup = "{ '_id' : ?#{#target} }")
Query: {"customer": {"$oid": "615c04e09b072503508c6321"}, "sample": {"$oid": "615c04e09b072503508c6322"}}

Reproducer:

@Test
void mapsDocumentReferences() {

	Customer customer = new Customer();
	customer.id = new ObjectId();
	customer.name = "wu";

	Sample sample = new Sample();
	sample.foo = new ObjectId().toString();

	org.bson.Document mappedQuery = mapper.getMappedObject(
			Criteria.where("customer").is(customer).and("sample").is(sample).getCriteriaObject(),
			context.getPersistentEntity(WithReference.class));
	// …
}

Object model

@Document
static class Customer {

	@Id
	private ObjectId id;
	private String name;
	private MyAddress address;
}

static class Sample {

	@Id private String foo;
}

@Document
static class WithReference {

	private ObjectId id;
	private String name;
	@DocumentReference(lookup = "{ 'name' : ?#{#target} }") // remove `lookup` for the other test case.
	private Customer customer;

	@DocumentReference
	private Sample sample;
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions