Description
Marcelo Grossi opened DATACOUCH-399 and commented
IndexManager is not respecting the configured TypeMapper in MappingCouchbaseConverter when creating secondary indices and views. It simply uses the classes fully qualified name (as below).
String typeKey = couchbaseOperations.getConverter().getTypeKey();
final String type = metadata.getDomainType().getName();
If one has a TypeMapper that makes use of the @TypeAlias
annotation this will make the implementation unusable as the converter will correctly use the type mapper to identify the type, but (in case of no-primary-key deployments) won't have a proper index to query on your entity.
package com.sample;
@Document
@TypeAlias("my-document")
public class MyDocument {
}
@Repository
@N1qlSecondaryIndexed(indexName = "my-document-index")
public interface MyDocumentRepository extends CouchbaseRepository<MyDocument, String> {
}
The example document/repository above expects documents created in Couchbase to have a "_class" field with the value "my-document" and a secondary index like:
CREATE INDEX `my-document-index` ON `my-bucket`(`_class`) WHERE (`_class` = "my-document")
But instead, the secondary index is created as:
CREATE INDEX `my-document-index` ON `my-bucket`(`_class`) WHERE (`_class` = "com.sample.MyDocument")
In deployments where there is no primary index available your data becomes unsearchable. Which makes the generated repository unusable.
I believe that exposing the TypeMapper on MappingCouchbaseConverter via simple getter should be enough to implement this. The code in IndexManager would look like:
CouchbaseDocument tempTypeHolder = new CouchbaseDocument();
couchbaseOperations.getConverter().getTypeMapper().writeType(metadata.getDomainType(), tempTypeHolder);
final String type = tempTypeHolder.get(typeKey).toString();
1 votes, 3 watchers