eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
229 stars 72 forks source link

[BUG] Parameters are not handled correctly when repository code is compiled with -parameters option #527

Closed OndroMih closed 2 months ago

OndroMih commented 2 months ago

Which JNoSQL project the issue refers to?

JNoSQL (Core)

Bug description

If the repository interface is compiled with -parameters argument, the parameter.isNamePresent() returns true in reflection utils. This is not handled properly in getParams and getBy methods.

Examples of problematic cases:

Jakarta Data TCK

In the Jakarta Data TCK, the test EntityTests.testFindList produces a wrong SelectQuery for semi-structured databases. PositiveIntegers.findOdd method contains 2 special parameters of type Limit and Sort. The resulting SelectQuery passed to the SemiStructuredTemplate methods contains an EQUALS condition, which contains 4 elements, instead of 2. The elements should contain only the 2 compared values, but they also contain the other 2 special parameters. This is because the TCK code is compiled with -parameters, the 2 special parameters thus have a name but aren't ignored when elements list is created.

Queries with ? parameters

For example the PersonRepository.findAge method in RepositoryReflectionUtilsTest in jnosql-mapping-core module's unit tests. If the repository interface is compiled with -parameters, then the test shouldFindByAge fails. This is because the detected params will contain the parameter under its name and not under ?1.

JNoSQL Version

1.1.2-SNAPSHOT

Steps To Reproduce

  1. Configure the jnosql-mapping-core module's compiler plugin to compile tests with the -parameters compiler argument. The test RepositoryReflectionUtilsTest.shouldFindByAge

Expected Results

  1. Even if the repository interface is compiled with -parameters, query methods with @Query and ? parameters should raise parameters that contain the appropriate ? parameter. For example, @Query("FROM Person WHERE age = ?1") should result in a query that has ?1 parameter.

Code example, screenshot, or link to a repository

To reproduce, add the following to the plugin configuration of the jnosql-mapping-core in pom.xml:

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-testCompile</id>
                        <configuration>
                            <compilerArgs>
                                <arg>-parameters</arg>
                            </compilerArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Then run mvn clean test.