1
I’m starting with Spring Boot and I’m trying to use it for a query where I want to check if two date columns are between a period provided by parameters. The code below works, but for this I have to repeat the parameters (start date and end date for comparison).
@Transactional(readOnly = true)
Collection<MyClass> findByDateBeginBetweenOrStartedWorkBetween (Instant firstDate, Instant lastDate, Instant firstDateAgain, Instant lastDateAgain);
I haven’t found any similar example so far. I figured it could be something like the excerpt below:
@Transactional(readOnly = true)
Collection<MyClass> findByDateBeginOrStartedWorkBetween (Instant firstDate, Instant lastDate);
But when I compile the project, I get the error below:
Caused by: java.lang.Illegalargumentexception: Failed to create query for method public Abstract java.util.Collection with... Myclass.findByDateBeginOrStartedWorkBetween (java.time.Instant,java.time.Instant)! No Parameter available for part startedWork BETWEEN (2): [Isbetween, Between] NEVER.
I can (and if so, how can I) use my comparison parameters only once using Spring Boot?
Opa, thanks for the answer. Yes the log already shows me the scenario, so much so that I passed 2x each date. I’m waiting to see if anyone else answers, because the intention is to see if it is possible to treat this scenario only using the nomenclature of the query via spring Boots. If no one pronounces, I will end with your answer as correct.
– WyllianNeo