在Cassandra中,列类型设置为Date,在Model类中,字段类型设置为具有getter和setter的java.util.Date。在此期间,com.datastax.driver.mapping.Mapper.save我收到以下异常:
Codec not found for requested operation: [date <-> java.util.Date]
Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [date <-> java.util.Date]
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:56)
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:25)
at com.datastax.driver.mapping.DriverThrowables.propagateCause(DriverThrowables.java:41)
at com.datastax.driver.mapping.Mapper.save(Mapper.java:272)
Run Code Online (Sandbox Code Playgroud)
在Google搜索过程中发现以下内容:
DATE <-> com.datastax.driver.core.LocalDate : use getDate()
Run Code Online (Sandbox Code Playgroud)
您必须将 java.util.Date 转换为com.datastax.driver.core.LocalDate
例子:
LocalDate localDate = LocalDate.fromMillisSinceEpoch(date.getTime());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5537 次 |
| 最近记录: |