question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

findById...AndXXX method derived query generates wrong statement

See original GitHub issue

I am looking at some Spring Data Couchbase integration issues in JHIpster project, and one particular issue I found is that when we have a repository method to find by id and any other property, the generated query is wrong.

As an example, the method findByIdIsNotNullAndActivatedIsTrue generates the following statement:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND id is not null and `activated`

In this scenario the Id should have meta(<bucket-name>) prepended:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND META(`testBucket`).`id` is not null and `activated`

To support these type of query, I believe that N1qlQueryCreator.java and QueryCriteria.java classes needs to be modified. QueryCriteria checks for backtics at start or end:

and if its not changed, it ends up adding backtics to the META: `META(`testBucket`).`id``)

I did an attempt to support this type of queries here:

and even though it works, I am not sure if its the right place for that change. I can probably create a PR with the fix if needed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mikereichecommented, Feb 5, 2021

Edit: I see you’re way ahead of me. Yes - make a PR and I’ll merge. I had just one comment.

@mmonti - is it important/helpful to you to get quick fixes in 4.1.x? Or just before the next release (which is February 17)? We could merge a quick-fix now as long as we got in a proper fix before then.

For https://github.com/spring-projects/spring-data-couchbase/issues/1066 - the issue about always back-ticking the ‘key’ of a QueryCriteria - the fix would be to accept a N1qlExpression as the key of a QueryCriteria (as well as the current String) - and propagate that change all the way through to where the maybeBackTic() method is called (it would just be a toString() on the N1qlExpression). [the quick fix would be just to check for “META(” in the string, ignoring case]

For https://github.com/spring-projects/spring-data-couchbase/issues/1072 - The PartTree processing of META properties (id and cas and expiration). The catch is that an entity could have a property named id (or cas or expiration), that isn’t the actual id, cas or expiration. And always substituting those for META().id etc. would be incorrect. The id can be handled by isIdProperty() and CAS can be isVersionProperty() but I don’t have a solution for expiration (maybe require the entity to contain a field annotated with @\Expiration, similar to @\Id and @\Version? Someone was asking for that already). [ the quick fix that would work for your case would just to do what I did with isIdProperty() (and the same with isVersionProperty())]

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to force oracle to use index range scan? - Stack Overflow
To "force" Oracle to use an index range scan, simply use an optimizer hint INDEX_RS_ASC . For example: CREATE TABLE mytable (a NUMBER...
Read more >
Spawn Jobs from a Procedure that run in parallel - Ask TOM
I have a table that contains 2 million transaction records. A procedure reads these transaction records and creates an output record in the...
Read more >
IBM Db2 Query Monitor for z/OS User's Guide
IBM® Db2 Query Monitor for z/OS® (also referred to as Db2 Query Monitor) is a query analysis tool that you can use to...
Read more >
RDF Semantics - W3C
An alternative way to specify a semantics is to give a ... Extensions or dialects of RDF which are obtained by imposing such...
Read more >
MySQL Reference Manual for version 3.23.6-alpha. - MIT
If you can't find something wrong with it, it's extremely likely that your current version of MySQL doesn't support the query you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found