Search code examples
solrcassandraspring-dataspring-data-cassandraspring-data-solr

Conflict between spring-data-cassandra and spring-data-solr


I'm currently working in project that needs Cassandra database to have search ability. We've got DataStax cluster and we want to use Spring Data to simplify database operations. However, when we made entity that got both - @Table (for cassandra) and @SolrDocument (for Solr) it happened to be broken. The only error we got is the one below. Anyone have encountered such a problem?

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type ENTITYNAME!

I know that this is probably Spring issue, but hope to find someone who have fought this type of problem. Greetings!

Some sample entity causing problems:

@SolrDocument(solrCoreName = "sample_entity")
@Table("sample_entity")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public final class SampleEntity {

    @PrimaryKey
    @Indexed(name = "id")
    private UUID id;

    private LocalDateTime created;

    private UUID foreignId;

    @Indexed(name = "name")
    private String name;

    private boolean someflag = true;
}

Solution

  • You're mixing up things - if you're using DSE Search, then it's better to perform search via CQL, by querying in the solr_query column. In your example, the @SolrDocument will force using of the Solr's HTTP API, while @Table will force use of CQL.

    You can use Object Mapper from DataStax to map classes to tables, like this:

    // STest.java
    @Table(keyspace = "test",name = "stest")
      public class STest {
        @PartitionKey
        private int id;
        private String t;
    }
    
    // STestAccessor.java
    @Accessor
    public interface STestAccessor {
        @Query("SELECT * FROM test.stest WHERE solr_query = :solr")
    
        Result<STest> getViaSolr(@Param("solr") String solr);
    }
    
    // STestMain.java
    MappingManager manager = new MappingManager(session);
    
    STestAccessor sa = manager.createAccessor(STestAccessor.class);
    Result<STest> rs = sa.getViaSolr("*:*");
    
    for (STest sTest : rs) {
        System.out.println("id=" + sTest.getId() + ", text=" + sTest.getT());
    }
    

    Here is the full code.