Spring Data Cassandra Reactive - " MappingException找不到类型类java.lang.Object"的PersistentEntity。

时间:2018-02-01 21:15:55

标签: spring spring-data spring-data-jpa datastax-java-driver spring-data-cassandra

我正在使用spring-boot-starter-data-cassandra-reactive v2.0.0.M7使用ReactiveApis与Cassandra进行交互。

我创建了Entity,Primarykey和Repository类。当我运行代码时,我遇到了以下异常。自从过去几个小时以来,我一直试图解决这个问题而没有任何成功。如果您需要更多信息,请告诉我。

Caused by: org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.Object!
    at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:76) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactory.getEntityInformation(ReactiveCassandraRepositoryFactory.java:103) ~[spring-data-cassandra-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactory.getTargetRepository(ReactiveCassandraRepositoryFactory.java:83) ~[spring-data-cassandra-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:300) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$3(RepositoryFactoryBeanSupport.java:287) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:141) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.util.Lazy.get(Lazy.java:63) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:290) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactoryBean.afterPropertiesSet(ReactiveCassandraRepositoryFactoryBean.java:99) ~[spring-data-cassandra-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    ... 20 common frames omitted

相关代码段

@Table(name = "scan")
@Getter @Setter @NoArgsConstructor @ToString
public class CScan {

    @PrimaryKey
    private CScanPrimaryKey toolSourceIdKey;

    @Column(name = "is_completed") 
    private String isCompleted;

    @Column(name = "update_date") 
    private LocalDateTime updateDate;

    @Column(name = "certification") 
    private String certification;

    @Column(name = "audit_updated") 
    private String auditUpdated;

    @Column(name = "sca_label") 
    private String scaLabel;

    @Column(name = "sca_buildId") 
    private String scaBuildId;

    @Column(name = "host_name") 
    private String hostName;

    @Column(name = "start_date") 
    private LocalDateTime startDate;

    @Column(name = "elapsed_time") 
    private int elapsedTime;

    @Column(name = "has_issue") 
    private String hasIssue;

    @Column(name = "updated") 
    private String updated;

    @Column(name = "sca_files") 
    private int scaFiles;

    @Column(name = "executable_loc") 
    private int executableLoc;

    @Column(name = "total_loc") 
    private int totalLoc;

    @Column(name = "engine_type") 
    private String engineType;

    @Column(name = "engine_version") 
    private String engineVersion;

    @Column(name = "guid") 
    private String guid;

    @Column(name = "project_label") 
    private String projectLabel;

    @Column(name = "version_label") 
    private String versionLabel;

    @Column(name = "proj_ver_id")
    private int projVerId;

    @Column(name = "proj_ver_name")
    private String projVerName;

    @Column(name = "proj_id")
    private int projId;

    @Column(name = "proj_name")
    private String projName;

    @Column(name = "artifact_id") 
    private int artifact_id;

    @Column(name = "object_version") 
    private int objectVersion;

    @Column(name = "migrated") 
    private String migrated;

    @Column(name = "server_version") 
    private Float serverVersion;

    @Column(name = "entry_name") 
    private String entryName;


    @Column(name = "fortify_annotations_loc") 
    private String fortifyAnnotationsLoc;

    @Column(name = "data_version") 
    private String dataVersion; 

}



@PrimaryKeyClass
@Getter @Setter @NoArgsConstructor @ToString @EqualsAndHashCode(exclude={})
public class CScanPrimaryKey implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 5703460462572087535L;

    @PrimaryKeyColumn(name = "tool_source_id", type = PrimaryKeyType.PARTITIONED)         
    private UUID toolSourceId;

    @PrimaryKeyColumn(name = "id", ordering = Ordering.ASCENDING)
    private int id; 

    @PrimaryKeyColumn(name = "upload_status", ordering = Ordering.ASCENDING)
    private String uploadStatus;    


}


@Repository
public interface ReactiveScanRepository<CScan> extends ReactiveCassandraRepository<CScan, CScanPrimaryKey> {

}

2 个答案:

答案 0 :(得分:1)

尝试使用Query Methods

您可以做类似的事情,

@Repository
public interface ReactiveScanRepository<CScan> extends ReactiveCassandraRepository<CScan, CScanPrimaryKey> {

    findByToolSourceId(@Param("toolSourceId") UUID toolSourceId);

    findByToolSourceIdAndUploadStatus(@Param("toolSourceId") UUID toolSourceId, @Param("uploadStatus") String uploadStatus);

}

查询方法应适用于大多数用例。对于精美的自定义查询,请使用@Query()

...    
    @Query("SELECT isCompleted from scan WHERE toolSourceId = :toolSourceId AND uploadStatus = :uploadStatus")
    Boolean findIsCopleteByToolSourceIdAndUploadStatus(@Param("toolSourceId") UUID toolSourceId, @Param("uploadStatus") String uploadStatus);
....

答案 1 :(得分:0)

我有同样的问题。我可以通过在类中放置一个断点来解决它

org.springframework.data.mapping.context.MappingContext

通过检查链,您将能够找到无法实例化的类。 对我来说,这是由于某个类未正确扩展“ ElasticsearchRepository”引起的:

import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

/***
 * Page visit repository
 * 
 * @author Michael Tnourji
 *
 */
public interface ElasticSearchRepo<T> extends ElasticsearchRepository<T, String> {

    public List<T> findByNameAndValue(String name, String value);
    public List<T> findByFieldAndIndex(String field, int index);
}