micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

Docs on `@Where` seem to point to wrong parameter format

Open csciuto opened this issue 3 years ago • 3 comments

Hello,

Quick one, I think!

Micronaut-Data-Model 2.3.1, JDK 11 (the docs seem the same in master) read

     * <p>Parameterized variables can be specified using the dollar syntax: {@code book_.enabled = ${enabled}}. In
     * this case the parameter must be declared in the method signature a compilation error will occur.</p>

If I do

@Repository
@Slf4j
@Where("@.accountId = ${accountId}")
public abstract class MyRepo implements CrudRepository<MyRecord, UUID> {

yields

io.micronaut.context.exceptions.ConfigurationException: Could not resolve placeholder ${accountId}

I went and looked at the tests for the annotation, and they suggest it should be :accountId I tried this and it works†. Are the docs off?

Thanks!

† of course it doesn't actually 'work' since the autogeneration of findById, existsById and deleteById now fail but that's a different problem.

csciuto avatar May 27 '21 19:05 csciuto

Yeah that’s not correct, you can move the annotation to the methods you want to have that

dstepanov avatar May 28 '21 00:05 dstepanov

Thanks for the quick reply @dstepanov !

To be clear (and this is pseudocode),

@Repository
public abstract class MyRepo implements CrudRepository<MyRecord, UUID> {

    @Where("@.accountId = ${accountId}")
    public abstract MyRecord findByMyIdAndAccountId(final UUID myId, final String accountId);
}

Returns

Could not resolve placeholder ${accountId}
io.micronaut.context.exceptions.ConfigurationException: Could not resolve placeholder ${accountId}
	at io.micronaut.context.env.DefaultPropertyPlaceholderResolver$PlaceholderSegment.getValue(DefaultPropertyPlaceholderResolver.java:260)

as well, but using :accountId instead of ${accountId} makes the tests pass.

This remains not a valid use case because @Where doesn't seem to add anything here because the dynamic method generation is already doing the right thing. Still... It still seems like the ${} syntax might be a documentation error.

csciuto avatar May 28 '21 01:05 csciuto

Using ${} is a documentation error.

graemerocher avatar May 28 '21 07:05 graemerocher

@dstepanov this issue seems fixed, as I can't find any ${} in the docs

Goldmensch avatar Sep 01 '22 15:09 Goldmensch