Cassandra使用LocalDate截断毫秒

问题描述 投票:0回答:1

我一直试图在Cassandra中存储直到毫秒的时间戳记值,但是我只能通过DataStax驱动程序获取到LocalDate为止,毫秒部分被省略了。

这是我的课程

package com.example.connectCass.Model;

import lombok.Data;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
import com.datastax.driver.core.LocalDate;


import java.util.Date;


@Data
@Table
public class DemoModel {

    @PrimaryKeyColumn(name = "acctID", type = PrimaryKeyType.PARTITIONED)
    private String acctID;
    @PrimaryKeyColumn(name = "transactionDate", type = PrimaryKeyType.PARTITIONED)
    private LocalDate transactionDate;
    @PrimaryKeyColumn(name = "currentTime", type = PrimaryKeyType.CLUSTERED)
    private LocalDate currentTime;

    @Column
    private String card;

    @Column
    private String amountCreditedFrom;

    @Column
    private double transactionAmount;

    @Column
    private double balance;

    public void setTransactionDate(){
        this.transactionDate = LocalDate.fromMillisSinceEpoch(new Date().getTime());
    }

    public void setCurrentTime(){
        this.currentTime = LocalDate.fromMillisSinceEpoch(new Date().getTime());
    }
}

setCurrentTime方法中,我希望时间到毫秒,但无法做到,只是到今天为止。直接尝试了java.util.Date,但是它不起作用。

为什么Cassandra中不存在毫秒?

java cassandra datastax
1个回答
0
投票

我错误地在表架构中定义了Date而不是Timestamp,这很糟糕。

© www.soinside.com 2019 - 2024. All rights reserved.