2017-02-02 19 views
0

我已經生成了使用cassandra作爲db的Microservice jhpister API。我已經使用yo jhipster生成了實體:entity entityname。在生成字段時,我將ZonedDateTime作爲字段CreatedOn的數據類型。所以它在Cassandra表中創建TimeStamp作爲數據類型,並在ZonedDateTime中創建java實體。我一直在使用BindStatement如何將java ZonedDateTime值設置爲Cassandra Timestamp字段

BatchStatement batch = new BatchStatement(); 
batch.add(insertStatement.bind() 
.setTimestamp("createdOn", existingWorkAssignment.getCreatedOn()); 

一些自定義插入代碼,但這個產生編譯它說不能解析方法監守我們設置的值是zoneddatetime但內部Cassandra的數據類型是時間戳時間誤差。請幫忙

回答

0

先將ZonedDateTime值轉換爲Timestamp所設定的值。

試着這樣做。 實施例:

ZonedDateTime dateTime =ZonedDateTime.from(ZonedDateTime.now()); 
Timestamp timestamp = Timestamp.valueOf(dateTime.toLocalDateTime()); 
System.out.println(timestamp); 

在你的情況

BatchStatement batch = new BatchStatement(); 
batch.add(insertStatement.bind() 
    .setTimestamp("createdOn", Timestamp.valueof(existingWorkAssignment.getCreatedOn().toLocalDateTime()); 
相關問題