Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colons in SQL strings in native queries doesn't work and can't be escaped (Postgres) #1354

Closed
rehnarama opened this issue Feb 24, 2022 · 1 comment · Fixed by #1356
Closed
Labels
type: enhancement New feature or request
Milestone

Comments

@rehnarama
Copy link

rehnarama commented Feb 24, 2022

Expected Behavior

You should be able to use colons as literals in SQL strings in native queries, or at least, escape them.

Actual Behaviour

Compiler complains about no method parameter found for whatever is after the colon.

This used to work in earlier version when on micronaut 2 (started seeing the error after migrating to micronaut 3)

Similar issue from a long time ago: #423 has there been a regression? 🤔

Steps To Reproduce

First an entity pointing to some table in

@MappedEntity("some_table")
public record ColonEntity(String example) {
}

And then the repository

@Repository("some_repository")
@JdbcRepository(dialect = Dialect.POSTGRES)
public interface SomeRepository {

    @Query(
        value = "SELECT 'one:two:three' as example",
        nativeQuery = true
    )
    ColonEntity reproduceColonError();

    @Query(
        value = "SELECT 'one\\:two\\:three' as example",
        nativeQuery = true
    )
    ColonEntity reproduceColonErrorEscaped();
}

Try to compile and you will get the error

Unable to implement Repository method: SomeRepository.reproduceColonError(). No method parameter found for named Query parameter: two

The same goes when trying to escape the colons in the second example function.

Environment Information

  • Windows
  • JDK 17.0.0
  • Micronaut data version=3.2.2
  • io.micronaut.data:micronaut-data-jdbc:3.2.2
  • io.micronaut.data:micronaut-data-model:3.2.2
  • io.micronaut.data:micronaut-data-processor:3.2.2
  • io.micronaut.data:micronaut-data-runtime:3.2.2
  • io.micronaut.data:micronaut-data-tx:3.2.2

Example Application

No response

Version

3.3.3

@graemerocher
Copy link
Contributor

graemerocher commented Feb 24, 2022

As a workaround you can put your queries in configuration, for example in application.yml:

my:
   query: "SELECT 'one:two:three' as example"

And repository:

    @Query(
        value = "${my.query}",
        nativeQuery = true
    )
    ColonEntity reproduceColonError();

@dstepanov dstepanov added the type: enhancement New feature or request label Mar 21, 2022
@dstepanov dstepanov added this to the 3.3.0 milestone Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants