rewrite-spring icon indicating copy to clipboard operation
rewrite-spring copied to clipboard

JDBC Query For long Replaced with Query For Object

Open Kushank24 opened this issue 11 months ago • 1 comments

What's changed?

queryforlong has been deprecated in Spring 5.3 versions and thus needs to be replaced with queryforobject

What's your motivation?

In my project I was getting this error and thus wrote a recipe to try this out

Anything in particular you'd like reviewers to focus on?

Currently, the recipe is not working because of following reasons and I am not able to debug it: JdbcTemplateQueryForLongMigrationTest > simpleTransformation() FAILED java.lang.IllegalStateException: LST contains missing or invalid type information MethodInvocation->NamedVariable->VariableDeclarations->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit /~~(MethodInvocation type is missing or malformed)~~>/jdbcTemplate.queryForLong(query) https://docs.openrewrite.org/reference/faq#im-seeing-lst-contains-missing-or-invalid-type-information-in-my-recipe-unit-tests-how-to-resolve at org.openrewrite.java.Assertions.assertValidTypes(Assertions.java:124) at org.openrewrite.java.Assertions.validateTypes(Assertions.java:61) at org.openrewrite.java.Assertions$$Lambda/0x000000b801187788.accept(Unknown Source) at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:301) at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:129) at com.flipkart.codelift.JdbcTemplateQueryForLongMigrationTest.simpleTransformation(JdbcTemplateQueryForLongMigrationTest.java:37)

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • [x] I've added unit tests to cover both positive and negative cases
  • [x] I've read and applied the recipe conventions and best practices
  • [x] I've used the IntelliJ IDEA auto-formatter on affected files

Kushank24 avatar Mar 19 '25 06:03 Kushank24

I've now made the tests runnable, but as you can see the recipe still does the wrong thing. I will let you take over from here again. Feel free to ask specific questions on Slack or here if you have problems.

knutwannheden avatar Mar 19 '25 17:03 knutwannheden