在Cassandra中使用UDT用户定义类型保存实体时出错

时间:2018-04-23 15:44:03

标签: cassandra datastax-java-driver user-defined-types spring-data-cassandra

我的Cassandra实体中有一个UDT:

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("schedule")
public class ScheduleEntity {
@PrimaryKey
private InstantKey key;

@Singular
@Column("days")
@CassandraType(type = DataType.Name.UDT, userTypeName = "schedule_day")
private List<Day> days;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@UserDefinedType("schedule_day")
public static class Day {
    @Column("day")
    private DayOfWeek day;

    @Singular
    @Column("periods")
    @CassandraType(type = DataType.Name.UDT, userTypeName = "schedule_period")
    private List<Period> periods;
}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@UserDefinedType("schedule_period")
public static class Period {
    @Column("from_time")
    private Long from;

    @Column("to_time")
    private Long to;

    @Column("x")
    private BigDecimal x;
}
}

当我尝试使用来自CassandraRepository的save方法保存实体时,我在单元测试中遇到此错误:

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/0:0:0:0:0:0:0:1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/0:0:0:0:0:0:0:1:9042] Cannot connect), localhost/127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:9042] Cannot connect))

我没有查找方法的这个问题,请问! PS:插入查询过程没有问题:

insert into schedule (id, year, instant, days)
values (99, 2018, '2018-04-16T16:44:49Z', [{day: 'MONDAY', periods: 
[{from_time: '9:00:00', to_time: '18:00:00', setpoint: 24.3}]}]);

0 个答案:

没有答案