I'm trying to make a case sensitive query in a repository that extends JpaRepository, in a Spring Boot 2 project with Spring Data JPA.
It's supposed that if I don't use IgnoreCase, the query should be case sensitive, but it doesn't occur.
Snippet:
log.info("Received name: " + name);
Player player = playerRepository.findByName(name).orElseThrow(()-> new NonExistingPlayerNameException(name));
log.info("Repository player name: " + player.getName());
Console result:
2020-03-19 13:05:02.831 INFO 13739 [...].controllers.PlayerController : Received name: peter
2020-03-19 13:05:02.884 INFO 13739 [...].controllers.PlayerController : Repository player name: Peter
As you can see, the query is case insensitive, but I want it case sensitive.
Am I doing anything wrong? How can I make the query case sensitive?
As a workaround, I can make the check after I receive the object and act in consequence, but I expected the query to be case sensitive.
Thanks in advance,
Carlos.
Edit:
Thanks for the answers and sorry about the missed information.
I'm using a MySQL database (mysql Ver 8.0.19-0ubuntu0.19.10.3 for Linux on x86_64 ((Ubuntu))) in a Ubuntu Desktop 19.10.
I'm sorry but I don't know how to log the actual query that gets executed.
What I can see is that the database allows me to save a register with upper and lower case, I can have a row with field name 'Peter' and another one with name 'peter'. I mean, the database seems that doesn't change the data to store it.
I will take a look at the answer about MSSQL Server.
Thank you,
Carlos.
Your problem not its in Spring, your problem is your Database.
See this link for more information
In this thread they explain how to change your database, or rather how to change the fields that you want to be sensitive
Is the LIKE operator case-sensitive with MSSQL Server?
Thank you all for all of the information and "clues" to find out the answer.
The problem was the collation: I was using utf8mb4_0900_ai_ci (case insensitive). I changed it to utf8mb4_es_0900_as_cs and everything works fine.
Thank you!!!
Carlos.
Related
I just can't find any info on this!!!
Please see the image. I want to capture the "number" from the user response as a variable (property) but can't see how to. Any ideas?!
I want to be able to do this within the composer, not with code. Surely #prebuilt number is storing the recognized entity - how do I set a variable (property) to the value of the entity? Thanks.
Here's the image of my issue
LOL - solved! The answer is to use coalesce. Keeping it here for reference for others.
Solution
In Elastic Search, to add new fields while running the application we have to provide
"dynamic":true
More info about the same: https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html
Is there any functionality which can replicate same behaviour in Vespa? I was not able to find in vespa documentation.
Kindly help me in this regard. Thank you.
https://docs.vespa.ai/en/schemas.html#schema-modifications is the best place to start - just modify the schema with new fields and redeploy the application. The new fields can not have a default value, they are empty. It is not necessary to restart Vespa, this can be done on a running instance.
Dynamic fields automatically created from data is not supported in Vespa. You should not use this; it's a malfeature.
If the data in question is structured, you can often achieve what you need here by using a map. Otherwise, it's easy and safe to add new fields to the schema and redeploy.
I am using "Send an HTTP Request to Sharepoint" action, and I want to filter the output to only include the project with ID = [user input filed in "Manually trigger a flow"]
My Uri seems to not be working and can't find errors; I have used this action before with no problems, can't figure what syntax (?) problem I may have?
Here is the Uri:
_api/ProjectData/Projects()?$Filter=ProjectUID eq '#{variables('proj id')}'&?Select=ProjectName,ProjectWorkspaceInternalUrl,ProjectUID,ProjectIdentifier
Can anyone spot the problem?!
Thanks so much in advance :)
For the URI try the following instead:
/_api/ProjectData/Projects()?$filter=ProjectId eq guid'xxxxx' &$Select=ProjectName,ProjectWorkspaceInternalUrl,ProjectId,ProjectIdentifier
where xxxx is your project id or in this case #{variables('proj id')}
It makes it easier to deal with the data as it doesn't return an array.
I am using spring reactive and need to check weather user with particular
data exists or not and currently I am not able to solve that problem.
Considering the scenerio
In my document I need to check if username or email already exists or not
In RDBS I can do it as
select count(id)>0 where username='abc' or email='abc#idx.com'
while using spring reactive which returns either mono or flux the simple most query becomes
{$or:[{"username":"abc"},{"email":"abc#idx.com"}]} which will return flux but I need boolean to verify from db
On solution is that I can get Flux<User> and the iterate it using form loop but then using ' result.block()' whick will block some other threads and therefore not a clean solution.
Is there any clean solution or any Idea how to solve this.
Thanks
Edit One possible solution can be creating unique indexing in monogdb, that I am using right now. But if there is any other solution please let me know
Using Spring Data MongoDB, you can use something like below:
public interface ReactiveUserRepository extends ReactiveSortingRepository<User, Long> {
Mono<User> findByUsernameAndEmail(String username, String email);
}
Find a single entity for the given criteria. It completes with IncorrectResultSizeDataAccessException on non-unique results.
You can refer to the complete syntax here:
https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/
I am doing a Spring web app and I use Spring Data.
I am able to use Spring Data to find objects by a single value of a field. For example:
some_object_repository.findByFirstName("John")
Is there any way I can provide two first names (e.g., "John", "David") similar to the following in concept:
some_object_repository.findByFirstName({"John", "David"})
without me writing a custom implementation?
Regards and thanks!
You can do this with In at the end
findByAgeIn(Collection ages) … where x.age in ?1
http://docs.spring.io/spring-data/jpa/docs/1.6.0.RELEASE/reference/html/jpa.repositories.html#jpa.query-methods
Section 2.3.2 Query creation
In your case it will be
findByFirstNameIn(Collection names)