cassandra日期类型的Java等效类型(映射)

时间:2017-06-27 17:28:00

标签: java datastax cql datastax-java-driver cassandra-3.0

我正在尝试在我的键空间中创建一个表,其中包含一个' date'使用cql键入cassandra。查询如下:

create table if not exists data(
    product_type varchar,
    end_date date,
    primary key(product_type,end_date)
);

现在我的Java模型类正在使用

  

com.datastax.driver.core.LocalDate

用于将cassandra日期字段映射到Java类型。

 @Column(name = "end_date")
    private com.datastax.driver.core.LocalDate endDate;

但是在运行代码时我遇到了一些异常。以下是异常的堆栈跟踪。

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: ['org.apache.cassandra.db.marshal.SimpleDateType' <-> com.datastax.driver.core.LocalDate]
    at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:741) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:588) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.CodecRegistry.access$500(CodecRegistry.java:137) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:246) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:232) [cassandra-driver-core-3.2.0.jar:]
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache.get(LocalCache.java:3934) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) [guava-16-mod.jar:]
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) [guava-16-mod.jar:]
    at com.datastax.driver.core.CodecRegistry.lookupCodec(CodecRegistry.java:522) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:485) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.AbstractGettableByIndexData.codecFor(AbstractGettableByIndexData.java:73) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.AbstractGettableByIndexData.get(AbstractGettableByIndexData.java:376) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.AbstractGettableData.get(AbstractGettableData.java:26) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.core.AbstractGettableData.get(AbstractGettableData.java:279) [cassandra-driver-core-3.2.0.jar:]
    at com.datastax.driver.mapping.Result.map(Result.java:56) [cassandra-driver-mapping-3.1.0.jar:]
    at com.datastax.driver.mapping.Result.all(Result.java:91) [cassandra-driver-mapping-3.1.0.jar:]
    at com.sial.datastax.jpa.SialDatastaxQuery.getResultList(SialDatastaxQuery.java:66) [SIAL-CDI-LOCAL-0.0.6.jar:]
    at com.sial.ecommerce.configurator.price.entities.beans.PriceDataBean.findByProductTypeAndSalesOrganization(PriceDataBean.java:170) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_51]
    at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_51]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    ... 91 more

我试图映射&#39; date&#39;在互联网上进行一些研究之后,在cassandra到com.datastax.driver.core.LocalDate中的字段。我试过这个链接来解决这个问题。但没有运气。 https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/pAoLlEzmGWA

我尝试使用java.util.Date,java.sql.Date进行映射。但是所有人都只给出了上述例外。

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException:

我正在使用datastax ver 3.4。

请帮我在java中为cassandra日期类型找到正确的映射器。

0 个答案:

没有答案