Spring Redis Data gives UncategorizedKeyValueException: nested exception is java.lang.NullPointerException - spring

I'm using redis as my secondary db in my spring application and i need to get all records that have null values for certain attributes. I create query in repository to achieve that.
method
findAllByCars(Integer c);
it works when using with integer as the param but when i use it to find all records that Cars is null.
repo.findAllByCars(null)
it's gives below error in stack trace.
rg.springframework.data.keyvalue.core.UncategorizedKeyValueException: nested exception is java.lang.NullPointerException
at org.springframework.data.keyvalue.core.KeyValuePersistenceExceptionTranslator.translateExceptionIfPossible(KeyValuePersistenceExceptionTranslator.java:49)
at org.springframework.data.keyvalue.core.KeyValueTemplate.resolveExceptionIfPossible(KeyValueTemplate.java:484)
at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:379)
at org.springframework.data.keyvalue.core.KeyValueTemplate.find(KeyValueTemplate.java:390)
Anyone can help this with?.

Related

using queries generated by name with Spring Boot

I am trying to write a query in Spring Boot, I have the query written like this
, but when I search for the vehicle objects by year by doing http://localhost:8080/vehicles?year=(year) it returns to me all of the vehicle objects instead of only ones that match the year.
Try this
http://localhost:8080/vehicles?year=2001
If still error try your query in sql command, i think any mistake in your query or check again in your controller file

Elasticsearch throwing an error during startup

I have implemented Elasticsearch in spring boot. On every server restart, I am getting the following error.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productController': Unsatisfied dependency expressed through field 'ps'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl': Unsatisfied dependency expressed through field 'pr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Rejecting mapping update to [products] as the final mapping would have more than 1 type: [_doc, product]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
I have deleted the index every time to start the server and then perform the index. Can anyone suggest to me what will the solution
Elasticsearch v6 and above cannot have more than one type per index. But from your exception, your mapping is trying to create more than one type on an index (_doc and product)
Refer https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html for more info.
As mentioned #Karthick from Elasticsearch 6.X more than one type per index is deprecated and only _doc internal and default mapping type is supported till version 7(for backward compatibility purpose) and that too will be completely removed from soon to be released 8.X major version.
You need to remove your own type name product to solve the issue.
As mentioned in the official link why it's removed.
In an Elasticsearch index, fields that have the same name in different
mapping types are backed by the same Lucene field internally. In other
words, using the example above, the user_name field in the user type
is stored in exactly the same field as the user_name field in the
tweet type, and both user_name fields must have the same mapping
(definition) in both types.
This can lead to frustration when, for example, you want deleted to be
a date field in one type and a boolean field in another type in the
same index.
On top of that, storing different entities that have few or no fields
in common in the same index leads to sparse data and interferes with
Lucene’s ability to compress documents efficiently.
For these reasons, we have decided to remove the concept of mapping
types from Elasticsearch.

Distinct Column Selection using Spring JPA Specifications and Pagination gives InvalidDataAccessApiUsageException

I am trying to filter results from a table based on a bunch of query parameters I receive using Spring Data JPA Specifications. I need to get results of Distinct Column which is of type UUID. All the other query params I need to query by are of type String.
So the repository method I try is findDistinctByTransactionId(Specficiation<T> spec, Pageable page)
I expect the result to be of type Page<UUID>. But I get an exception. The error message is :
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [org.springframework.data.jpa.domain.Specifications#7c900524] did not match expected type [java.util.UUID (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [org.springframework.data.jpa.domain.Specifications#7c900524] did not match expected type [java.util.UUID (n/a)]
So the problem here is the way to let the JPA know that the Distinct Column we are looking for is of type UUID.
The problem is that you are trying to combine two distinct feature of Spring Data JPA: Specifications and Query Derivation. This does not work.
What you should do is create a custom method implementation of your method which constructs a query using the JPA Criteria API and then adds the predicate you pass in as an argument.

EhCache Exception

I am getting the below exception while using searchable with net.sf.ehcache:ehcache:2.9.0
net.sf.ehcache.config.InvalidConfigurationException: Search attributes
not supported by this store type: net.sf.ehcache.store.disk.DiskStore
Can Somebody help!

How to write a spring data jpa query method with a negated enum constant?

I'd like to query a database using a Spring Data JPA query method and retrieve the records which do not have a certain enum value. What's working is
findBySuggestionNot(Suggestion suggestion, Pageable pageable);
and then I hand in e.g. Suggestion.rejected.
What I want is
findBySuggestionNotRejected(Pageable pageable);
But this results in an error because "NotRejected" is not a property of Suggestion. Any pointers?
Using full-qualified name instand of XENUM.XXX, eg:
where a.status= com.foo.bar.Status.ACTIVED
And Be Careful, your enum should be uppercase ranther then lowercase ,camel case, otherwise the exception like "invalid path com.foo.bar.Status.ACTIVED ..." would be throw by spring. I am using Spring Boot 2.1.1.RELEASE

Resources