cassandra:java类在使用cassandra时抛出invaliddataaccessapiusageexception

col17t5w  于 2021-06-14  发布在  Cassandra
关注(0)|答案(0)|浏览(291)

我正在使用SpringBoot和cassandra来保存数据。但是我的db模型不能与cassandra的注解一起工作。
我的web服务使用Java11和Cassandra3.11.4。
casdbnode类

@ToString
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Table("node")
public class CasDBNode{

    @PrimaryKeyColumn(ordinal = 0, name = "id", type = PrimaryKeyType.PARTITIONED)
    private String id;

    @PrimaryKeyColumn(ordinal = 1, name = "config_id", type = PrimaryKeyType.PARTITIONED)
    private String configId;

    @Column
    private String name;

    @Column
    private NodeType type;

    @Column
    private List<? extends NodeResponse> responses;

    @Column("parent_node")
    private String parentNode;

    @Column
    private String conditions;

    @Column("previous_sibling")
    private String previousSibling;

    @Column("api_url")
    private String apiUrl;

    @Column
    private List<NodeQuestion> questions;

}

类simplenodequestion

@ToString
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@UserDefinedType
public class SimpleNodeQuestion implements NodeQuestion {

    private String title;

    private String output;

    @Column("context_name")
    private String contextName;

    private String condition;

    @Column("option_api")
    private String optionApi;

    @Column("default_options")
    private List<Option> defaultOptions;

}

我看到一些添加@userdefinetype的解决方案应该可以工作,但是我仍然得到了错误

Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cassandraTemplate' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Only primitive types are allowed inside Collections for property [questions] of type ['interface java.util.List'] in entity [com.jamesaq12wsx.IBS_Backend.model.db.CasDBNode]

更新

在搜索解决方案之后,我更改了注解和错误消息
casdbnode类

@ToString
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Table(value = "node")
public class CasDBNode extends CasDBBaseData implements DBNode{

    @PrimaryKeyColumn(ordinal = 0, name = "id", type = PrimaryKeyType.PARTITIONED)
    private String id;

    @PrimaryKeyColumn(ordinal = 1, name = "config_id", type = PrimaryKeyType.PARTITIONED)
    private String configId;

    @Column
    private String name;

    @Column
    private NodeType type;

    @Column
    private List<? extends NodeResponse> responses;

    @Column("parent_node")
    private String parentNode;

    @Column
    private String conditions;

    @Column("previous_sibling")
    private String previousSibling;

    @Column("api_url")
    private String apiUrl;

    @CassandraType(type = DataType.Name.LIST, typeArguments = DataType.Name.UDT, userTypeName = "question")
    private List<DBNodeQuestion> questions;
}

类casdbnodequestion

@UserDefinedType(value = "question")
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class CasDBNodeQuestion implements DBNodeQuestion {

    private String title;

    private String output;

    private String contextName;

    private String condition;

    private String optionApi;

    @CassandraType(type = DataType.Name.LIST, userTypeName = "option")
    private List<DBOption> defaultOptions;

}

错误消息更改为

nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cassandraTemplate' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Invocation of init method failed; 
nested exception is org.springframework.data.mapping.MappingException: User type [question] not found

更新

我换了衣服 interfaceclass 而且很有效。
我不知道这是不是问题,但任何帮助将非常感谢和感谢提前!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题