Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
春季及;Couchbase-未找到能够从[java.lang.Long]类型转换为[java.sql.Timestamp]类型的转换器_Java_Spring Data Jpa_Spring Data_Spring Data Couchbase - Fatal编程技术网

春季及;Couchbase-未找到能够从[java.lang.Long]类型转换为[java.sql.Timestamp]类型的转换器

春季及;Couchbase-未找到能够从[java.lang.Long]类型转换为[java.sql.Timestamp]类型的转换器,java,spring-data-jpa,spring-data,spring-data-couchbase,Java,Spring Data Jpa,Spring Data,Spring Data Couchbase,我们有一个保存到Couchbase数据库的文档。它有一个时间戳字段: @Document class Cat{ @Id @GeneratedValue(strategy = GenerationStrategy.UNIQUE) private String id; @Field Timestamp birthdateTimestamp; 我们可以在创建Cat时将数据保存到字段中: Timestamp currentTimestamp = new Timestamp(new Date().

我们有一个保存到Couchbase数据库的文档。它有一个时间戳字段:

@Document
class Cat{

@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
private String id;

@Field
Timestamp birthdateTimestamp;
我们可以在创建Cat时将数据保存到字段中:

 Timestamp currentTimestamp = new Timestamp(new Date().getTime());
 Cat cat = Cat.builder().birthdateTimestamp(currentTimestamp).build();
 catRepository.save(cat);  // extends CouchbaseRepository<Cat, String>
Timestamp currentTimestamp=new Timestamp(new Date().getTime());
Cat=Cat.builder().birthdateTimestamp(currentTimestamp.build();
catRepository.save(cat);//扩展CouchbaseRepository
并且该字段可以在数据库中正确显示-
“birthdateTimestamp”:1564570366644

但是,当尝试从数据库读取
Cat
时,我们会得到以下错误:

org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型[java.lang.Long]转换为类型[java.sql.Timestamp]]的转换器,其根本原因是 org.springframework.core.convert.ConverterNotFoundException:未找到能够从类型[java.lang.Long]转换为类型[java.sql.Timestamp]的转换器 位于org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) 位于org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) 位于org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) 位于org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.readValue(MappingCouchbaseConverter.java:804) 位于org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.access$400(MappingCouchbaseConverter.java:77) 位于org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter$CouchbasePropertyValueProvider.getPropertyValue(MappingCouchbaseConverter.java:869) 位于org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter$CouchbasePropertyValueProvider.getPropertyValue(MappingCouchbaseConverter.java:824) 位于org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:71) 位于org.springframework.data.mapping.model.SpELExpressionParameterValueProvider.getParameterValue(SpELExpressionParameterValueProvider.java:49) 位于org.springframework.data.convert.classgeneratingtityinstantiator$entityInstanceorAdapter.extractInvocationArguments(classgeneratingtityinstantiator.java:248) 位于org.springframework.data.convert.classgeneratingtityinstantiator$entityInstanceorAdapter.createInstance(classgeneratingtityinstantiator.java:221) 位于org.springframework.data.convert.classgeneratingTitingInstantiator.createInstance(classgeneratingTitingInstantiator.java:86) 位于org.springframework.data.couchbase.core.convert.mappingcouchbasecoverter.read(mappingcouchbasecoverter.java:236) 位于org.springframework.data.couchbase.core.convert.mappingcouchbasecoverter.read(mappingcouchbasecoverter.java:213) 位于org.springframework.data.couchbase.core.convert.mappingcouchbasecoverter.read(mappingcouchbasecoverter.java:171) 位于org.springframework.data.couchbase.core.convert.mappingcouchbasecoverter.read(mappingcouchbasecoverter.java:77) 位于org.springframework.data.couchbase.core.CouchbaseTemplate.mapToEntity(CouchbaseTemplate.java:700) 位于org.springframework.data.couchbase.core.CouchbaseTemplate.findByN1QL(CouchbaseTemplate.java:448) 位于org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeCollection(AbstractN1qlBasedQuery.java:156) 位于org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeEntity(AbstractN1qlBasedQuery.java:162) 位于org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.ExecutedPendingEntype(AbstractN1qlBasedQuery.java:135) 位于org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.execute(AbstractN1qlBasedQuery.java:106) 位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590) 位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.data.couchbase.repository.support.ViewPostProcessor$ViewInterceptor.invoke(ViewPostProcessor.java:87) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) 位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185) 位于org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 位于com.sun.proxy.$Proxy130.findbycustomername和projectname(未知源)


我们做错了什么?

看起来该值以历元格式存储在数据库中

而不是试图转换epo
@Field
long birthdateTimestamp;
new Timestamp(object.getBirthdateTimestamp())