How to use QueryByExampleExecutor with spring-data-elasticsearch - spring-boot

I want to use QueryByExampleExecutor with ElasticsearchRepository but I am getting Exception when building SpringBootApplication.
I am using Gradle with below dependencies:
springboot 2.2.4.RELEASE
spring-boot-starter-data-elasticsearch
My repository:
#Repository
public interface OrdersRepository extends ElasticsearchRepository<Orders, String>,
QueryByExampleExecutor {
Page<Orders> findByCustomerFirstNameIgnoreCase(String customerFirstName, Pageable pageable);
Page<Orders> findByCustomerLastNameIgnoreCase(String customerLastName, Pageable pageable);
Page<Orders> findByOrderNo(Long orderNo, Pageable pageable);
}
My controller in which I am using example-by-query implementation method:
#PostMapping("search/any")
public Iterable<Orders> searchByAnyText
(#RequestBody Orders orders) {
final Example<Orders> ordersExample = Example.of(orders);
return repo.findAll(ordersExample);
}
This is my Orders class:
#JsonIgnoreProperties(ignoreUnknown = true)
#Data
#Document(indexName = "#{#indexName}",
type = "#{#typeName}")
public class Orders {
#Id
private String orderHeaderKey;
#Version
private Long createdAt;
private Long updatedAt;
private String createuserid;
private String allAddressesVerified;
private String modifyuserid;
private String customerZipCode;
private String customerFirstName;
private String orderType;
#Field(type = FieldType.Object)
private PersonInfoBillTo personInfoBillTo;
#Field(type = FieldType.Object)
private List<OrderDate> orderDates;
private String minOrderStatus;
private String multipleStatusesExist;
private String sourceIPAddress;
private String hasDeliveryLines;
private String minOrderStatusDesc;
private String returnByGiftRecipient;
private String enterpriseCode;
private String paymentStatus;
private String taxExemptionCertificate;
private String status;
private String taxPayerId;
private String hasProductLines;
#Field(type = FieldType.Object)
private List<OrderLine> orderLines;
private String hasServiceLines;
private String customerEMailID;
private String notificationType;
private String sellerOrganizationCode;
private String createts;
private String orderName;
private String billToKey;
private Long orderNo;
private String searchCriteria1;
private String originalTotalAmount;
private String searchCriteria2;
private String maxOrderStatus;
private String draftOrderFlag;
private String enteredBy;
private String processPaymentOnReturnOrder;
private String customerPhoneNo;
private String hasDerivedChild;
private String noOfAuthStrikes;
private String documentType;
private String purpose;
private String maxOrderStatusDesc;
private String customerPONo;
private String hasPendingChanges;
private String orderDate;
private String customerRewardsNo;
private String entryType;
private String modifyts;
private String orderComplete;
private String customerLastName;
private String notificationReference;
private String allocationRuleID;
private String paymentRuleId;
private String billToID;
private String holdFlag;
private String overallStatus;
}
I am getting below exception(pasting parts of exception) on running application:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordersRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property exists found for type Orders!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
.
.
. ... 19 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property exists found for type Orders!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_221]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]

Related

CQEngine Query nested object using parser.retrieve

I have a nested object like
public class SQSMessage implements Serializable {
private String type;
private boolean isEntity;
private String eventType;
private SystemInfo systemInfo;
private DomainAttributes domainAttributes;
#Data
public static class SystemInfo implements Serializable {
private String identifier;
private String ownedBy;
private Payload payload;
private EntityTags entityTags;
private long createdOn;
private String createdBy;
private long version;
private long lastUpdatedOn;
private String lastUpdatedBy;
private String attrEncKeyName;
#Data
public static class Payload implements Serializable {
private String bucketName;
private String objName;
private String encKeyName;
private byte[] payloadBytes;
private byte[] decryptedBytes;
private byte[] sanitizedBytes;
}
#Data
public static class EntityTags implements Serializable {
private List<Tag> tags;
#Data
public static class Tag implements Serializable {
private String tagName;
private String tagValue;
}
}
}
#Data
public static class DomainAttributes implements Serializable {
private String updatedByAuthId;
private String saveType;
private String docName;
private String ceDataType;
private String year;
private String appId;
private String formSetId;
private String appSku;
private String deviceId;
private String deviceName;
}
}
I would like to query the collection of SQSObjects by applying a filter like
ResultSet<SQSMessage> results = parser.retrieve(indexedSQSMessage, "SELECT * FROM indexedSQSMessage WHERE type='income' and DomainAttributes.saveType in ('endSession', 'cancelled')or (DomainAttributes.countryCode is null or DomainAttributes.countryCode='US'");
Is that possible using CQEngine? if yes.. please send me the examples.
The reason why I want o make that as sql... where clause is dynamic for various use cases.
Your example is more complicated than it needs to be for the question, so I am just skimming it. (Read about SSCCE)
However generally this kind of thing should be possible. See this related question/answer for how to construct nested queries: Can CQEngine query an object inside another object
If you set up attributes like that, you should be able to use them in SQL queries as well as programmatically.

Spring Data Cassandra Not handling raw UDTS, throws no suitable converter exception

After upgrading to Spring 2.4.0 , spring data Cassandra is throwing no suitable converter found exception
Here is my UDT
#Setter
#Getter
#ToString
#NoArgsConstructor
#UserDefinedType(value="ADDRESS")
#AllArgsConstructor
public class Address implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String address1;
private String address2;
private String state;
private String city;
private String country;
private String zip;
private String longitude;
private String latitude;
}
Here is my main table
package com.sellingsimplified.msor.common.schema;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.NotEmpty;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.CassandraType.Name;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
#Getter
#Setter
#ToString
#Table(value = "#{#contactCassandra}")
#Document(indexName = "#{#contactIndex}")
#JsonIgnoreProperties(ignoreUnknown = true)
public class Contact implements Serializable,MSOREntity {
/**
*
*/
private static final long serialVersionUID = 5141439096729821675L;
#PrimaryKey
#Id
private Long contactid;// 1
private Long companyid;// 1
#CassandraType(type =Name.UDT, userTypeName = "NAME")
#Field(type = FieldType.Auto, includeInParent = true)
private com.sellingsimplified.msor.common.schema.Name contactname;// 1
#javax.validation.constraints.Email
private String corpemail;// 1
#CassandraType(type = Name.UDT, userTypeName = "EMAIL")
#Field(type = FieldType.Auto, includeInParent = true)
private Email contactemail;// 1
#NotEmpty(message="Jobtitle cannot be empty")
private String jobtitle;
private String skill;// newly added field
#CassandraType(type =Name.UDT, userTypeName = "ADDRESS")
#Field(type = FieldType.Auto, includeInParent = true)
#Column("contactaddress")
private Address contactaddress;
#CassandraType(type = Name.UDT, userTypeName = "PHONE")
#Field(type = FieldType.Auto, includeInParent = true)
private Phone contactphone;
private String companyname;
/**
* linkedinurl, facebookurl, twitterurl, xing_url, viadeo_url, misc_url
*/
private Map<String, String> contactsocialurl;
private String twitterhandle;
private String jobfunction;
private String createdby;
private String modifiedby;
private Date createdon;
private Date modifiedon;
private String updatedby;
private Date updatedon;
private String status;
private String contactverificationstatus;
private String copyaddress;
private String contactverified;
private String emailverified;
private String phonenumberverified;
private String senioritylevel;
private String contactsource;
private String lastmodifiedsystem;
private String domain;
private String comment;
private String processstatus;
private String enrichmentstage;
private String thresholdstatus;
private String incomingemailtype;
private String pageaccessedby;
private String groupid;
private String emailpattern;
private String emailcheck;
private String websitedomain;
private String humanhelp;
private String notVerifiedreason;
private String notVerifiedcomment;
private String zone;
private String companycheck;
private String industry;
private String employeetotal;
#CassandraType(type =Name.UDT, userTypeName = "NAME")
#Field(type = FieldType.Object, includeInParent = true)
private com.sellingsimplified.msor.common.schema.Name contactnamenl;
private String jobtitlenl;
#CassandraType(type = Name.UDT, userTypeName = "ADDRESS")
#Field(type = FieldType.Auto, includeInParent = true)
private Address contactaddressnl;
private String contacthash;
private String sourceurl;
#CassandraType(type = Name.UDT, userTypeName = "COMPANY")
#Field(type = FieldType.Auto, includeInParent = true)
private Company contactcompany;
private Long tokenid = -1L;
// new fields
private Map<String, String> customfields;
private Map<String, String> flags;
private Set<String> usertags;
private Set<String> systemtags;
private String user;
private String chromeuser;
private String experience;
private String notes;
#CassandraType(type = Name.UDT, userTypeName = "JobHistory")
#Field(type = FieldType.Auto, includeInParent = true)
private List<JobHistory> jobhistory;
private List<EmailHistory> emailhistory;
private String contactidtxt;
private Date lastaccessedate;
private Date ecmverifiedon;
private Date verifiedon;
private String isactive;
private String isverified;
private String isarchived;
private String isdeleted;
private Set<Long> mergedcontactids;
private String emaildomain;
private String contactotherfield1;
private String contactotherfield2;
private String contactotherfield3;
private String contactotherfield4;
private String contactotherfield5;
private String contactotherfield6;
private String contactotherfield7;
private String contactotherfield8;
private String contactotherfield9;
private String contactotherfield10;
private String linkedinurl;
private String facebookurl;
private String twitterurl;
private String miscurl;
private String linkedinhandle;
private String facebookhandle;
private String xinghandle;
private String viadeolinkhandle;
private String srcemail;
// new fields
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((contacthash == null) ? 0 : contacthash.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Contact other = (Contact) obj;
if (contacthash == null) {
if (other.contacthash != null)
return false;
} else if (!contacthash.equals(other.contacthash))
return false;
return true;
}
#Override
public EntityType entityType() {
// TODO Auto-generated method stub
return EntityType.CONTACT;
}
#Override
public String hash() {
// TODO Auto-generated method stub
return contacthash;
}
}
Address is a User Defined Type and used in Table contact.
I am extending AbstractCassandraConfiguration to create Cassandra configutaion
package com.sellingsimplified.msor.common.cassandra;
import java.time.Duration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
import org.springframework.boot.autoconfigure.cassandra.CqlSessionBuilderCustomizer;
import org.springframework.boot.autoconfigure.cassandra.DriverConfigLoaderBuilderCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CqlSessionFactoryBean;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.SessionBuilderConfigurer;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
#Configuration
#ConditionalOnProperty(value = "cassandra.enable", havingValue = "true", matchIfMissing = false)
#EnableCassandraRepositories(basePackages = "com.sellingsimplified.msor.common.repository")
public class CassandraConfig extends AbstractCassandraConfiguration {
#Value("${cassandra.table.contact:CONTACT}")
private String contactCassandra;
#Value("${cassandra.table.company:COMPANY}")
private String companyCassandra;
#Value("${spring.data.cassandra.contact-points}")
private String contactPoints;
#Value("${spring.data.cassandra.port}")
private int port;
#Value("${spring.data.cassandra.keyspace}")
private String keySpace;
#Value("${spring.data.cassandra.username}")
private String username;
#Value("${spring.data.cassandra.password}")
private String password;
#Value("${spring.data.cassandra.schema-action}")
private String schemaAction;
#Value("${cassandra.table.contact.history:ContactHistory}")
private String contactHistoryCassandra;
#Value("${cassandra.table.company.history:CompanyHistory}")
private String companyHistoryCassandra;
#Override
protected String getKeyspaceName() {
return keySpace;
}
#Override
protected String getContactPoints() {
return contactPoints;
}
#Override
protected int getPort() {
return port;
}
#Override
public SchemaAction getSchemaAction() {
return SchemaAction.valueOf(schemaAction);
}
protected boolean getMetricsEnabled() {
return false;
}
#Bean(name = "companyCassandra")
public String companyCassandra() {
return companyCassandra;
}
#Bean(name = "contactHistoryCassandra")
public String contactHistoryCassandra() {
return contactHistoryCassandra;
}
#Bean(name = "companyHistoryCassandra")
public String companyHistoryCassandra() {
return companyHistoryCassandra;
}
#Bean(name = "contactCassandra")
public String contactCassandra() {
return contactCassandra;
}
#Bean
public CqlSessionBuilderCustomizer authCustomizer(CassandraProperties properties) {
return (builder) -> builder.withAuthCredentials(properties.getUsername(), properties.getPassword());
}
#Bean
#Override
public CqlSessionFactoryBean cassandraSession() {
CqlSessionFactoryBean cassandraSession = super.cassandraSession();// super session should be called only once
cassandraSession.setUsername(username);
cassandraSession.setPassword(password);
cassandraSession.setLocalDatacenter("DC1");
return cassandraSession;
}
#Override
public String[] getEntityBasePackages() {
return new String[] { "com.sellingsimplified" };
}
#Override
protected SessionBuilderConfigurer getSessionBuilderConfigurer() {
return new SessionBuilderConfigurer() {
#Override
public CqlSessionBuilder configure(CqlSessionBuilder cqlSessionBuilder) {
return cqlSessionBuilder.withConfigLoader(DriverConfigLoader.programmaticBuilder()
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(15000))
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofSeconds(100))
.withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false)
.withDuration(DefaultDriverOption.METADATA_SCHEMA_REQUEST_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_AGREEMENT_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, Duration.ofSeconds(100)).build());
}
};
}
#Bean
DriverConfigLoaderBuilderCustomizer cassandraDriverCustomizer() {
return (builder) -> builder
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofSeconds(100))
.withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false)
.withDuration(DefaultDriverOption.METADATA_SCHEMA_REQUEST_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_AGREEMENT_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(100))
.withDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, Duration.ofSeconds(100));
}
}
I am getting below exception while saving Contact Object
Caused by: org.springframework.data.cassandra.CassandraUncategorizedException: No converter found capable of converting from type [com.sellingsimplified.msor.common.schema.Address] to type [com.datastax.oss.driver.api.core.data.UdtValue]; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.sellingsimplified.msor.common.schema.Address] to type [com.datastax.oss.driver.api.core.data.UdtValue]
at org.springframework.data.cassandra.core.cql.CassandraExceptionTranslator.translate(CassandraExceptionTranslator.java:160) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.cql.CassandraExceptionTranslator.translateExceptionIfPossible(CassandraExceptionTranslator.java:72) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.config.CqlSessionFactoryBean.translateExceptionIfPossible(CqlSessionFactoryBean.java:646) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.3.1.jar:5.3.1]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) ~[spring-tx-5.3.1.jar:5.3.1]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152) ~[spring-tx-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.1.jar:5.3.1]
at com.sun.proxy.$Proxy135.save(Unknown Source) ~[na:na]
at com.sellingsimplified.msor.marchingengine.consumer.MSORGatewayEndpoint.processLead(MSORGatewayEndpoint.java:70) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171) ~[spring-messaging-5.3.1.jar:5.3.1]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120) ~[spring-messaging-5.3.1.jar:5.3.1]
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48) ~[spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:321) ~[spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.invoke(BatchMessagingMessageListenerAdapter.java:170) ~[spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:162) ~[spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:58) ~[spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchOnMessage(KafkaMessageListenerContainer.java:1744) [spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessageWithRecordsOrList(KafkaMessageListenerContainer.java:1735) [spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessage(KafkaMessageListenerContainer.java:1693) [spring-kafka-2.6.3.jar:2.6.3]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchListener(KafkaMessageListenerContainer.java:1622) [spring-kafka-2.6.3.jar:2.6.3]
... 7 common frames omitted
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.sellingsimplified.msor.common.schema.Address] to type [com.datastax.oss.driver.api.core.data.UdtValue]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322) ~[spring-core-5.3.1.jar:5.3.1]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195) ~[spring-core-5.3.1.jar:5.3.1]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175) ~[spring-core-5.3.1.jar:5.3.1]
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.convertIfNecessary(ConvertingPropertyAccessor.java:120) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.getProperty(ConvertingPropertyAccessor.java:91) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:744) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeMapFromWrapper(MappingCassandraConverter.java:490) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:456) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.StatementFactory.insert(StatementFactory.java:307) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:632) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:622) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.save(SimpleCassandraRepository.java:93) ~[spring-data-cassandra-3.1.1.jar:3.1.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:289) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:524) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:531) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:156) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.4.1.jar:2.4.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.1.jar:5.3.1]
at com.sun.proxy.$Proxy135.save(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.1.jar:5.3.1]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.1.jar:5.3.1]
... 26 common frames omitted
You will need to implement a class annotated with #Entity that is mapped to your UDT.
Have a look at the Entities page of the Java driver docs for details. Cheers!

Hibernate : Unable to locate appropriate constructor on class

i want to retrieve data with DTO Projection using sprind data jpa, but unfortunately when i call the method an error has occurred :
[2020-05-28 21:02:03] Unable to locate appropriate constructor on class [com.burgerbuilder.backend.DTO.Response.UserResponse]. Expected arguments are: java.util.UUID, java.lang.String , java.lang.String , java.lang.String , java.util.Collection
[select new com.burgerbuilder.backend.DTO.Response.UserResponse(u.id,u.email,u.name,u.lastName,u.authorities) from com.burgerbuilder.backend.Model.User u where u.id=:id]
my repository :
#Repository
public interface UserRepository extends JpaRepository<User, UUID> {
#Query("select new com.burgerbuilder.backend.DTO.Response.UserResponse(u.id,u.email,u.name,u.lastName,u.authorities) from User u where u.id=:id")
Optional<UserResponse> findUserById(#Param("id") String id);}
User class:
#Entity
public class User implements UserDetails {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Type(type=”uuid-char”)
private UUID id;
#NotNull
private String email;
#NotNull
private String password;
private String name;
private String lastName;
private String phoneNumber;
private String emailVerificationToken;
private boolean isEmailVerified=false;
private boolean isPhoneNumberVerified=false;
#OneToMany(mappedBy = “user”,cascade = CascadeType.ALL)
private List<Authority> authorities=new ArrayList();
DTO Class :
public class UserResponse {
private String userId;
private String email;
private String name;
private String lastName;
private List<Authority> authorities=new ArrayList<>();
public UserResponse(UUID userId, String email, String name, String lastName, List<Authority> authorities) {
this.userId = userId.toString();
this.email = email;
this.name = name;
this.lastName = lastName;
this.authorities=authorities;
}
}
can someone help me please ?

Spring Data JPA Mapping Exception No Dialect mapping for JDBC type: -9

I am trying to use a projection and am getting the following error. Not sure what the issue is.
Here is the projection:
public interface UserMini {
Long getApproverKey();
String getEmailAddress();
String getFirstName();
String getLastName();
Long getUserKey();
String getUserName();
}
Here is the Query in the repository:
#RestResource(path="getUserMini")
#Query(value="SELECT approverKey, emailAddress, firstName, lastName, userKey, userName FROM [dbo].BdmUser WHERE userKey = :userKey ", nativeQuery=true)
UserMini getUserMini(#Param("userKey") long userKey);
Here is the Entity
#Table (name="[BdmUser]")
#Entity
public class BdmUser {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private Long userKey;
private Long priceListKey;
private String firstName;
private String lastName;
private String userName;
private String emailAddress;
private String password;
private Boolean active;
private Long approverKey;
private BigDecimal orderLimit;
private Long salesOfficeKey;
private Long reportsToId;
private Boolean requiresOrderApproval;
private Date lastLoginDate;
private String rowIsCurrent;
private Date rowStartDate;
private Date rowEndDate;
#Column(name="HashByteValueType1", updatable=false, insertable=false)
private String hashByteValueType1;
#Column(name="HashByteValueType2", updatable=false, insertable=false)
private String hashByteValueType2;
private String rowChangeReason;
#Column(name="DQScoreKey")
private Integer dqScoreKey;
private Integer insertAuditKey;
private Integer updateAuditKey;
Try to cast the NVARCHAR to VARCHAR in your query
CONVERT(varchar,theNVarcharColumn)

Nested Mapping in Mapstruct

I am new to MapStruct API, can anyone say how to do nested Mapping.
I have two classes one is my actual purchaseOrder class, which is known my target class, the other is EDPurchaseOrder class which known as source file, here don't worry about the naming conventions I used, just go with source and target files.
Source Classes
Source class EDCustomerOrder and its reference classes
public class EDCustomerOrder{
private Integer orderID;
private String orderNumber;
private BigDecimal orderTotalQty;
private String UOM;
private PickupDTO pickupPoints;
private Integer supplierID;
private String supplierName;
private String supplierNature;
private EDAddress supplierEDAddress;
}
public class EDPickup{
private List<EDPOItem> items;
}
public class EDAddress{
private String addressLine1;
private String addressLine2;
private String addressLine3;
private String city;
private String state;
private string countryCode;
private String country;
private String postalCode;
}
public class EDPOItem{
private Integer itemID;
private String itemCode;
private String itemDescription;
private Integer itemQuantity;
}
Target classes
Here my target class CustomerOrder and its reference classes
public class CustomerOrder{
private Integer orderID;
private String orderNumber;
private List<Pickup> pickupPoints;
private Supplier supplierDetail;
}
public class Pickup{
private Integer pickupID;
private Integer pickupLocationNumber;
private List<POItem> items;
}
public class POItem{
private Integer itemID;
private String itemCode;
private String itemDescription;
private Integer itemQuantity;
}
public class Supplier{
private Integer supplierID;
private String supplierName;
private String supplierNature;
private Address supplierAddress;
}
public class Address{
private String addressLine1;
private String addressLine2;
private String addressLine3;
private String city;
private String state;
private string countryCode;
private String country;
private String postalCode;
}
So I suppose you have the same hierarchy of objects on the target side, e.g. a SongDTO, LibraryDTO and TrackDTO.
Then you'd have to declare a mapping method for each of those pairs of corresponding objects, configuring it via #Mapping as needed:
public interface MyMapper {
#Mapping(source="name", target="title")
SongDTO songToDto(Song song);
LibraryDTO libraryToDto(Library library);
TrackDTO trackToDto(Track track);
}
Then e.g. the generated implementation of songToDto() will invoke libraryToDto() in order to map the song's library into the song DTO's library DTO.
Also check out the reference guide to learn more.
#Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CandidateProfessionalEntityAndDTOMapper {
#Mappings({
#Mapping(source = "company.companyId", target = "companyId"),
})
Clazz1
entityToReferencesMapping(Clazz2 entity);
}
public class Clazz2 {
private String companyName;
private Company company;
}
public class Company{
Integer companyId;
}
public class Clazz1 {
private String companyId;
private String companyName;
}

Resources