Open dsuepke-swisscom opened 2 weeks ago
I’ve already completed the development to address this issue, and the changes are ready to be submitted in a PR. If the issue is valid, would it be okay for me to propose the changes via the PR?
@Seol-JY How do you plan to address the issue? What changes do you want to propose? Let's please discuss these upfront.
@dsuepke-swisscom to your question:
One query method uses named queries while the other declares a query string. That is a significant difference for us. To be able to apply sorting, we need to be in control over the actual query string. JPA's EntityManager
allows us only calling EntityManager.createNamedQuery(queryName)
after which we can only bind parameters and set limit/offset. We cannot alter the query itself.
In the second case, where you provide a SQL string, we are parsing the SQL query and injecting the given sort order.
Another aspect is that named queries are often associated times with additional information (e.g., @NamedNativeQuery(resultSetMapping = …, fetchSize = …,
) so we cannot extract the query and run the query as it was a pure String-based query.
Let me know whether this makes sense.
Thank you for your clarification, @mp911de
I had initially developed a solution assuming this was a valid issue, with changes ready for implementation. However, after reviewing your explanation of how named queries and string-based queries are handled differently - particularly regarding sort order capabilities and metadata handling - I now understand that the current warning behavior is intentional and technically correct. I'll withdraw my proposed changes as they would have added unnecessary warnings that don't align with the actual technical implementation. Thank you for clarifying the architectural reasoning behind this difference.
Hi, thanks to the both of you. I understand the technical limitations and it makes sense, was kinda expecting this to be the underlying cause. So the warning itself is correct and I appreciate it. Possibly, there is still room for improvement:
In summary, I think two follow-up issues arise from your helpful explanations: a) The warning should indicate at a solution rather than the problem, and b) there must be a way to get rid of the warning once it has been solved to keep a clean log.
In that regard, what actually is the recommended course of action? In the real application we are indeed using a resultSetMapping, inlining does not seem possible as the normal Query annotation does not support it.
Thanks for the detail. Have you tried switching to our new @NativeQuery
annotation (available in the latest milestones and RC1 release). It allows to specify @NativeQuery(sqlResultSetMapping=…)
.
Alternatively, you could switch to Limit
and ScrollPosition
parameters while returning Window<T>
.
Once you can confirm that @NativeQuery(sqlResultSetMapping=…)
is working for you, we could update our log message to include this suggestion.
Sorry, had to work on another project for a few days. I would like to try @NativeQuery
, but I cannot figure out how to import that into our gradle project. We have these two, which seem relevant:
plugins {
id 'org.springframework.boot' version '3.3.0'
...
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
...
}
I cannot find an RC on mavencentral. I found some release notes on the JPA site, but no instructions on how to use it. Could you kindly help me on how to use the mentioned RC for NativeQuery?
EDIT: Changed the plugin, copied the wrong line.
The easiest might be going to start.spring.io and generating a new Gradle project with Boot 3.4 RC1. That allows you to copy the milestone repo declaration. Am 15. Nov. 2024, 08:37 +0100 schrieb dsuepke-swisscom @.***>:
Sorry, had to work on another project for a few days. I would like to try @NativeQuery, but I cannot figure out how to import that into our gradle project. We have these two, which seem relevant: plugins { id 'com.github.node-gradle.node' version '3.6.0 ... } dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' ... } I cannot find an RC on mavencentral. I found some release notes on the JPA site, but no instructions on how to use it. Could you kindly help me on how to use the mentioned RC for NativeQuery? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Hi,
I have two basically equivalent queries. One of them (
findFoo
) gives a warning on startup, one (findFoo2
) doesn't. The warning seems to be correct, because in our project the query gets very slow.Specific issues:
findFoo2
is missing correctly or incorrectly.:findFoo
not work? Both of them are virtually the same.Minimal example:
Log output
FooRepository
FooEntity
build.gradle