This question is related to Custom Repository Implementation
I have created a custom repo
public interface CustomTransactionRepo<TEntity> {
List<TEntity> basicSearch(String searchQuery, String searchColumn, Class<TEntity> collectionType);
}
Its implementation:
@Repository
public class CustomTransactionRepoImpl<TEntity> implements CustomTransactionRepo<TEntity> {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public List<TEntity> basicSearch(String searchQuery, String searchColumn, Class<TEntity> en) {
var query = new Query();
var criteria = new ArrayList<Criteria>();
if (StringUtils.isNotEmpty(searchQuery)) {
criteria.add(Criteria.where(searchColumn)
.regex(searchQuery, "i"));
}
query.addCriteria(new Criteria().andOperator(criteria.toArray(new Criteria[0])));
var simRecords = mongoTemplate.find(query, en);
return simRecords;
}
}
I have a BaseJPA repo that extends my CustomRepo (CustomTransactionRepo) and MongoRepository
@NoRepositoryBean
public interface BaseJpaRepo<TEntity> extends CustomTransactionRepo<TEntity>, MongoRepository<TEntity, String> {
}
and finally MyRepository (SimRecordRepository) that just only need to extend BaseJpaRepo
@Repository
public interface SimRecordRepository extends BaseJpaRepo<SimRecord> {
}
and I am calling this repo from my service layer:
@Service
public class TransactionServiceImpl implements TransactionService {
@Autowired
private SimRecordRepository repo;
@Override
public List<SimRecord> basicSearch(String searchQuery, String searchColumn) {
return repo.basicSearch(searchQuery, searchColumn, SimRecord.class);
}
}
My Entity SimRecord:
@Document(collection = "sim_record")
public class SimRecord {
private String id;
private String system;
private String entity;
@Field("business_ref")
private String businessRef;
private String recordSetId;
private Object payload;
private String payloadType;
private Object canonical;
private String canonicalType;
private String processingStatus;
private String recordStatus;
private String resultType;
private String classValue;
// Getters and Setters
Now while running the build i am getting the exception:
org.springframework.data.mapping.PropertyReferenceException: No property 'basicSearch' found for type 'SimRecord'
I am unsure what else need to done.
What i expected was that the i should be able to call the method basicSarch()
but instead got that propertyReference Exception
Ansh Raina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.