'Cassandra Spring No Converter Found Capable of Converting from Type Instant to type Long
Am getting a No converter found capable of converting from type Instant to type Long while using Spring and Cassandra.
I have 2 Instant fields writtenDate (in the object primary key) and hotelAddedDate in the object. However, I do not have any Long fields; thus, I am a little confused.
Does anyone have an idea how to fix this error?
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.Instant] to type [java.lang.Long]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.convertIfNecessary(ConvertingPropertyAccessor.java:120)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.getProperty(ConvertingPropertyAccessor.java:91)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:771)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeInternal(MappingCassandraConverter.java:518)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeInternal(MappingCassandraConverter.java:513)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:484)
at org.springframework.data.cassandra.core.StatementFactory.insert(StatementFactory.java:308)
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:674)
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:664)
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.save(SimpleCassandraRepository.java:96)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:289)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:529)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:639)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:163)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy199.save(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy199.save(Unknown Source)
at com.saathratri.tajvote.service.impl.CustomerReviewsByHotelAndLastNameAndFirstNameServiceImpl.save(CustomerReviewsByHotelAndLastNameAndFirstNameServiceImpl.java:36)
at com.saathratri.tajvote.service.impl.CustomerReviewsByHotelAndLastNameAndFirstNameServiceImpl$$FastClassBySpringCGLIB$$da12f07b.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at com.saathratri.tajvote.aop.logging.LoggingAspect.logAround(LoggingAspect.java:105)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698)
at com.saathratri.tajvote.service.impl.CustomerReviewsByHotelAndLastNameAndFirstNameServiceImpl$$EnhancerBySpringCGLIB$$eda9c521.save(<generated>)
at com.saathratri.tajvote.web.rest.CustomerReviewsByHotelAndLastNameAndFirstNameResource.createCustomerReviewsByHotelAndLastNameAndFirstName(CustomerReviewsByHotelAndLastNameAndFirstNameResource.java:77)
at com.saathratri.tajvote.web.rest.CustomerReviewsByHotelAndLastNameAndFirstNameResource$$FastClassBySpringCGLIB$$d91d43fd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
...
Here is my CQL for creating the table in Cassandra:
create table customer_reviews_by_hotel_and_last_name_and_first_name (
hotel_id uuid,
last_name text,
first_name text,
written_date timestamp,
review_id timeuuid,
customer_id uuid,
customer_email_addresses set<text>,
customer_phone_numbers set<text>,
added_source text,
main_star_rating tinyint,
comments text,
enjoyed_stay boolean,
would_recommend boolean,
hotel_added_date timestamp,
hotel_name text,
hotel_email text,
hotel_phone_number text,
primary key((hotel_id), last_name, first_name, written_date, review_id))
with clustering order by (last_name desc, first_name desc, written_date desc, review_id asc);
This is my primary key class:
package com.saathratri.tajvote.domain;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
@PrimaryKeyClass
public class CustomerReviewsByHotelAndLastNameAndFirstNameId
implements java.io.Serializable {
@PrimaryKeyColumn(
name = "hotel_id",
ordinal = 0,
type = PrimaryKeyType.PARTITIONED
)
@CassandraType(type = CassandraType.Name.UUID)
private UUID hotelId;
@PrimaryKeyColumn(
name = "last_name",
ordinal = 1,
type = PrimaryKeyType.CLUSTERED
)
@CassandraType(type = CassandraType.Name.TEXT)
private String lastName;
@PrimaryKeyColumn(
name = "first_name",
ordinal = 2,
type = PrimaryKeyType.CLUSTERED
)
@CassandraType(type = CassandraType.Name.TEXT)
private String firstName;
@PrimaryKeyColumn(
name = "written_date",
ordinal = 3,
type = PrimaryKeyType.CLUSTERED
)
@CassandraType(type = CassandraType.Name.BIGINT)
private Instant writtenDate;
@PrimaryKeyColumn(
name = "review_id",
ordinal = 4,
type = PrimaryKeyType.CLUSTERED
)
@CassandraType(type = CassandraType.Name.UUID)
private UUID reviewId;
public CustomerReviewsByHotelAndLastNameAndFirstNameId() {}
public CustomerReviewsByHotelAndLastNameAndFirstNameId(
UUID hotelId,
String lastName,
String firstName,
Instant writtenDate,
UUID reviewId
) {
this.hotelId = hotelId;
this.lastName = lastName;
this.firstName = firstName;
this.writtenDate = writtenDate;
this.reviewId = reviewId;
}
public UUID getHotelId() {
return this.hotelId;
}
public void setHotelId(UUID hotelId) {
this.hotelId = hotelId;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Instant getWrittenDate() {
return this.writtenDate;
}
public void setWrittenDate(Instant writtenDate) {
this.writtenDate = writtenDate;
}
public UUID getReviewId() {
return this.reviewId;
}
public void setReviewId(UUID reviewId) {
this.reviewId = reviewId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CustomerReviewsByHotelAndLastNameAndFirstNameId)) {
return false;
}
CustomerReviewsByHotelAndLastNameAndFirstNameId customerReviewsByHotelAndLastNameAndFirstNameId = (CustomerReviewsByHotelAndLastNameAndFirstNameId) o;
return (
Objects.equals(
hotelId,
customerReviewsByHotelAndLastNameAndFirstNameId.hotelId
) &&
Objects.equals(
lastName,
customerReviewsByHotelAndLastNameAndFirstNameId.lastName
) &&
Objects.equals(
firstName,
customerReviewsByHotelAndLastNameAndFirstNameId.firstName
) &&
Objects.equals(
writtenDate,
customerReviewsByHotelAndLastNameAndFirstNameId.writtenDate
) &&
Objects.equals(
reviewId,
customerReviewsByHotelAndLastNameAndFirstNameId.reviewId
)
);
}
@Override
public int hashCode() {
return Objects.hash(hotelId, lastName, firstName, writtenDate, reviewId);
}
// prettier-ignore
@Override
public String toString() {
return "CustomerReviewsByHotelAndLastNameAndFirstNameId{" +
", hotelId='" + getHotelId() + "'" +
", lastName='" + getLastName() + "'" +
", firstName='" + getFirstName() + "'" +
", writtenDate='" + getWrittenDate() + "'" +
", reviewId='" + getReviewId() + "'" +
"}";
}
}
This my domain class:
package com.saathratri.tajvote.domain;
import java.io.Serializable;
import java.time.Instant;
import java.util.Set;
import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
/**
* A CustomerReviewsByHotelAndLastNameAndFirstName.
*/
@Table("customer_reviews_by_hotel_and_last_name_and_first_name")
public class CustomerReviewsByHotelAndLastNameAndFirstName
implements Serializable {
private static final long serialVersionUID = 1L;
@PrimaryKey
private CustomerReviewsByHotelAndLastNameAndFirstNameId id;
@Column("customer_id")
@CassandraType(type = CassandraType.Name.UUID)
private UUID customerId;
@Column("customer_email_addresses")
@CassandraType(
type = CassandraType.Name.SET,
typeArguments = CassandraType.Name.TEXT
)
private Set<String> customerEmailAddresses;
@Column("customer_phone_numbers")
@CassandraType(
type = CassandraType.Name.SET,
typeArguments = CassandraType.Name.TEXT
)
private Set<String> customerPhoneNumbers;
@Column("added_source")
@CassandraType(type = CassandraType.Name.TEXT)
private String addedSource;
@Column("main_star_rating")
@CassandraType(type = CassandraType.Name.TINYINT)
private Integer mainStarRating;
@Column("comments")
@CassandraType(type = CassandraType.Name.TEXT)
private String comments;
@Column("enjoyed_stay")
@CassandraType(type = CassandraType.Name.BOOLEAN)
private Boolean enjoyedStay;
@Column("would_recommend")
@CassandraType(type = CassandraType.Name.BOOLEAN)
private Boolean wouldRecommend;
@Column("hotel_added_date")
@CassandraType(type = CassandraType.Name.BIGINT)
private Instant hotelAddedDate;
@Column("hotel_name")
@CassandraType(type = CassandraType.Name.TEXT)
private String hotelName;
@Column("hotel_email")
@CassandraType(type = CassandraType.Name.TEXT)
private String hotelEmail;
@Column("hotel_phone_number")
@CassandraType(type = CassandraType.Name.TEXT)
private String hotelPhoneNumber;
public CustomerReviewsByHotelAndLastNameAndFirstNameId getId() {
return id;
}
public void setId(CustomerReviewsByHotelAndLastNameAndFirstNameId id) {
this.id = id;
}
public CustomerReviewsByHotelAndLastNameAndFirstName id(
CustomerReviewsByHotelAndLastNameAndFirstNameId id
) {
this.id = id;
return this;
}
// jhipster-needle-entity-add-field - JHipster will add fields here
public UUID getCustomerId() {
return this.customerId;
}
public CustomerReviewsByHotelAndLastNameAndFirstName customerId(
UUID customerId
) {
this.setCustomerId(customerId);
return this;
}
public void setCustomerId(UUID customerId) {
this.customerId = customerId;
}
public Set<String> getCustomerEmailAddresses() {
return this.customerEmailAddresses;
}
public CustomerReviewsByHotelAndLastNameAndFirstName customerEmailAddresses(
Set<String> customerEmailAddresses
) {
this.setCustomerEmailAddresses(customerEmailAddresses);
return this;
}
public void setCustomerEmailAddresses(Set<String> customerEmailAddresses) {
this.customerEmailAddresses = customerEmailAddresses;
}
public Set<String> getCustomerPhoneNumbers() {
return this.customerPhoneNumbers;
}
public CustomerReviewsByHotelAndLastNameAndFirstName customerPhoneNumbers(
Set<String> customerPhoneNumbers
) {
this.setCustomerPhoneNumbers(customerPhoneNumbers);
return this;
}
public void setCustomerPhoneNumbers(Set<String> customerPhoneNumbers) {
this.customerPhoneNumbers = customerPhoneNumbers;
}
public String getAddedSource() {
return this.addedSource;
}
public CustomerReviewsByHotelAndLastNameAndFirstName addedSource(
String addedSource
) {
this.setAddedSource(addedSource);
return this;
}
public void setAddedSource(String addedSource) {
this.addedSource = addedSource;
}
public Integer getMainStarRating() {
return this.mainStarRating;
}
public CustomerReviewsByHotelAndLastNameAndFirstName mainStarRating(
Integer mainStarRating
) {
this.setMainStarRating(mainStarRating);
return this;
}
public void setMainStarRating(Integer mainStarRating) {
this.mainStarRating = mainStarRating;
}
public String getComments() {
return this.comments;
}
public CustomerReviewsByHotelAndLastNameAndFirstName comments(
String comments
) {
this.setComments(comments);
return this;
}
public void setComments(String comments) {
this.comments = comments;
}
public Boolean getEnjoyedStay() {
return this.enjoyedStay;
}
public CustomerReviewsByHotelAndLastNameAndFirstName enjoyedStay(
Boolean enjoyedStay
) {
this.setEnjoyedStay(enjoyedStay);
return this;
}
public void setEnjoyedStay(Boolean enjoyedStay) {
this.enjoyedStay = enjoyedStay;
}
public Boolean getWouldRecommend() {
return this.wouldRecommend;
}
public CustomerReviewsByHotelAndLastNameAndFirstName wouldRecommend(
Boolean wouldRecommend
) {
this.setWouldRecommend(wouldRecommend);
return this;
}
public void setWouldRecommend(Boolean wouldRecommend) {
this.wouldRecommend = wouldRecommend;
}
public Instant getHotelAddedDate() {
return this.hotelAddedDate;
}
public CustomerReviewsByHotelAndLastNameAndFirstName hotelAddedDate(
Instant hotelAddedDate
) {
this.setHotelAddedDate(hotelAddedDate);
return this;
}
public void setHotelAddedDate(Instant hotelAddedDate) {
this.hotelAddedDate = hotelAddedDate;
}
public String getHotelName() {
return this.hotelName;
}
public CustomerReviewsByHotelAndLastNameAndFirstName hotelName(
String hotelName
) {
this.setHotelName(hotelName);
return this;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getHotelEmail() {
return this.hotelEmail;
}
public CustomerReviewsByHotelAndLastNameAndFirstName hotelEmail(
String hotelEmail
) {
this.setHotelEmail(hotelEmail);
return this;
}
public void setHotelEmail(String hotelEmail) {
this.hotelEmail = hotelEmail;
}
public String getHotelPhoneNumber() {
return this.hotelPhoneNumber;
}
public CustomerReviewsByHotelAndLastNameAndFirstName hotelPhoneNumber(
String hotelPhoneNumber
) {
this.setHotelPhoneNumber(hotelPhoneNumber);
return this;
}
public void setHotelPhoneNumber(String hotelPhoneNumber) {
this.hotelPhoneNumber = hotelPhoneNumber;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CustomerReviewsByHotelAndLastNameAndFirstName)) {
return false;
}
return (
id != null &&
id.equals(((CustomerReviewsByHotelAndLastNameAndFirstName) o).id)
);
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "CustomerReviewsByHotelAndLastNameAndFirstName{" +
"id=" + getId() +
", customerId='" + getCustomerId() + "'" +
", customerEmailAddresses='" + getCustomerEmailAddresses() + "'" +
", customerPhoneNumbers='" + getCustomerPhoneNumbers() + "'" +
", addedSource='" + getAddedSource() + "'" +
", mainStarRating=" + getMainStarRating() +
", comments='" + getComments() + "'" +
", enjoyedStay='" + getEnjoyedStay() + "'" +
", wouldRecommend='" + getWouldRecommend() + "'" +
", hotelAddedDate='" + getHotelAddedDate() + "'" +
", hotelName='" + getHotelName() + "'" +
", hotelEmail='" + getHotelEmail() + "'" +
", hotelPhoneNumber='" + getHotelPhoneNumber() + "'" +
"}";
}
}
Solution 1:[1]
Had to change CassandraType.Name.BIGINT to CassandraType.Name.TIMESTAMP:
In CustomerReviewsByHotelAndLastNameAndFirstName.java:
...
@Column("hotel_added_date")
@CassandraType(type = CassandraType.Name.TIMESTAMP)
private Instant hotelAddedDate;
...
In CustomerReviewsByHotelAndLastNameAndFirstNameId.java:
...
@PrimaryKeyColumn(
name = "written_date",
ordinal = 3,
type = PrimaryKeyType.CLUSTERED
)
@CassandraType(type = CassandraType.Name.TIMESTAMP)
private Instant writtenDate;
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amar Premsaran Patel |